In Interface Builder when I look at the size inspector for the view, it's showing 320x416 and it's grayed out so I can't change it. How can this be made editable?
Change the UIView's "Size" in the "Simulated Metrics" area in the inspector to "Freeform". Then you can change the Width and Height in "View" area in the inspector.
if you have any of the metrics (status bar, top navigation bar, etc) it won't let you resize the view.
Related
My code:
#IBOutlet weak var scroller: NSScrollView!
var showSettingsButton = NSButton(frame: NSMakeRect(0, 860, 60, 40))
showSettingsButton.title = "Settings"
scroller.addSubview(showSettingsButton)
The button looks as intended by the scrollview keeps static, but when I scroll the ScrollView, the button just looks like this:
I want to put this button always in the down-left corner regardless of scroller's scrolling.
So which view should be the superView of this button?
It should be in your View. Put it underneath the Scroll View - Text View, but make sure it will be siblings with the Scroll View - Text View, and not a child.
If you're going to add it in code, add it like
view.addSubview(showSettingsButton)
For your requirement , you should subclass NSScrollView and override the "tile" method. There you can specify your buttons frame
When you want your Button not to scroll, why do you add it to the scroll view then?
Add it to view, the superview of scrollview. So make it a sibling of the scrollview. Just add the scrolliview first and the button next so that the button overwrites the scrollview and appears on top.
ViewController
-> View
-> ScrollView
-> TextView (and anything that you want to scroll)
-> Button
You may want to do parts of this programmatically because IB or Storyboard Editor respectivey may change the view hierarchy again by making the button a subview of your scroll view.
I saw this effect today where the navigation bar title seemingly starts within the view, then shrinks and moves upwards into the navigation bar's title as you scroll the page, it then reverses to its original state when scrolled back to the top.
Does anyone have any insight on how this is done? Is a navigation bar used at all, or is it being mocked using a UIView that shrinks in height and the background colour darkens? Perhaps the title is a label converted to a UIImage and scaled down rather than the font size decreasing?
Just speculating on possible techniques.
Would love to get some opinions on this. Thanks in advance.
Yes, You can change the size of the font and the origin of the Navigation Bar in accordance with your gesture recognizer.
navigationBar.frame.origin.y = -10
will shift the Navigation bar up by 10 points. The font can be changed using
if let font = UIFont(name: "Lato-Light.ttf", size: 34) {
UINavigationBar.appearance().titleTextAttributes = [NSFontAttributeName: font]
}
This format is because using a forced unwrap ! will crash the app with UIFont
In this context, font can be a variable where you call the normal init with same typeface and different size.
These two operations should be performed whenever the gesture recognizer updates its value or scroll position. You may or may not have to redraw the view, however.
What would be the best way to create content and scroller insets on an NSScrollView like one can set on a UIScrollView?
I'd like to be able to add a footer which is not spanned by the vertical scroller like that found at the bottom of Mail.app's sidebar
Have an NSView that contains both your NSScrollView and your footer's view, with the scroll view's frame set to not overlap the footer.
How to change the width of UITabBarItem?
I have an item with the title, that is wider than default item width. How can I fix it?
Solution for iOS7 and greater versions:
A new property has been introduced for UITabBar: itemWidth.
Set the itemWidth to a positive value to be used as the width for tab
bar items when they are positioned as a centered group (as opposed to
filling the tab bar). Default of 0 or values less than 0 will be
interpreted as a system-defined width.
#property(nonatomic) CGFloat itemWidth NS_AVAILABLE_IOS(7_0) UI_APPEARANCE_SELECTOR;
So you can do this in your AppDelegate:
[[UITabBar appearance] setItemWidth:WIDTH];
If you want to fill the whole UITabBar:
[[UITabBar appearance] setItemWidth:self.window.frame.size.width/NUMBER_OF_ITEMS];
You can change the spacing (and width) of the tab bar items by subclassing UITabBar and overriding its layoutSubviews method. You will find all tab bar buttons in the self.subViews array. Their class is the non-public UITabBarButton but they inherit from UIControl so you can identify all tab bar buttons checking if they are kind of UIControl class. Then all you need is to change the frame of the tab bar buttons.
I just searched through the documentation and saw no method for adjusting the UITabBarItem's width.
A possible solution would be to place a view within the tab bar controller to load a custom UITabBarItem, that is the proper width.
Found easier solution for swift if you subclass the UITabBarController
this will autofill the tab bar items evenly
self.tabBar.itemPositioning = .fill
Swift 5
UITabBar().itemWidth = self.window!.frame.size.width/5
How can I set the vertical scroller style in NSScrollView?
If you're using Interface Builder, deselect "automatically hide scrollers". The scroll bars then become visible. Click a scroll bar and edit its control size attributes in the inspector.
If you're doing this in code:
NSScrollView* myScrollView = ...;
[[myScrollView verticalScroller] setControlSize: NSSmallControlSize]; // or whatever
Yes you can set the size in Xcode.
Or rather in Interface Builder:
Make sure to expand the objects panel on the left.
Then you can see two NSScroller objects in the scroll view.
Just select them and set the control size in the Inspector Panel to Small or Mini.