Set vertical scroller style in NSScrollView - objective-c

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.

Related

UIView in UITableView disappear when becomes firstResponder

In storyboard I have a UITableViewController-->UITableView-->UITableViewSecion--> with static cells
in the same UITableView I also have a UIView that holds a background image and UITextView.
A click on a button shows the UIView and set it's frame, which appears OK, but as soon as I click on the UITextView or make it firstResponder programmatically the keyboard appears and the view disappears
the code when clicking the button
self.myView.frame = CGRectMake(0, self.tableView.contentOffset.y+100, self.tableView.frame.size.width, self.tableView.frame.size.height-100);
self.myView.hidden = NO;
how can I fix this?
Can you copy paste us the code where you add the view to the tableview? Are you doing it with constraints or with frames?
The issue you are having is probably due to the fact the UITableViewControllers automatically shrink the contentSize of the UITableView they hold when the keyboard shows. If you add a UIView to your tableView with addSubview: programmatically, you might need to add a flexible bottom resize mask to make sure when the contentSize shrinks in height, your view stays attached to the top and not the bottom.
Try this on viewDidLoad:
[theViewYouAddedToTableView setAutoresizingMask:UIViewAutoresizingFlexibleBottomMargin];

How to use NSScrollview?

I can't figure out how to actually use NSScrollview. I dragged the scroll view object onto an NSWindow in the interface builder. I then dragged some NSButtons onto the scroll view. My question is:
How do I actually make it scroll down, for example, 2x the original height?
Of course the user can scroll automatically using their UI. I assume what you want to do is to scroll programmatically.
A bit of background: An NSScrollView has a documentView, which is the underlying view that the scroll view shows a part of, and a clipView, which is the view that is shown on the screen. So the clip view is like a window into the document view. To scroll programmatically you tell the document view to scroll itself in the clip view.
You have two options on how to scroll programmatically:
- (void)scrollPoint:(NSPoint)aPoint –– This scrolls the document so the given point is at the origin of the clip view that encloses it.
- (BOOL)scrollRectToVisible:(NSRect)aRect –– This scrolls the document the minimum distance so the entire rectangle is visible. Note: This may not need to scroll at all in which case it returns NO.
So, for example, here is an example from Apple's Scroll View Programming Guide on how to scroll to the bottom of the document view. Assuming you have an IBOutlet called scrollView connected up to the NSScrollView in your nib file you can do the following:
- (void)scrollToBottom
{
NSPoint newScrollOrigin;
if ([[scrollview documentView] isFlipped]) {
newScrollOrigin = NSMakePoint(0.0,NSMaxY([[scrollview documentView] frame])
-NSHeight([[scrollview contentView] bounds]));
} else {
newScrollOrigin = NSMakePoint(0.0,0.0);
}
[[scrollview documentView] scrollPoint:newScrollOrigin];
}

How to change the width of UITabBarItem?

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 to change UIView size in Interface Builder

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.

NSScrollView clipping overlaid UI elements

I have a button that sits on top of an NSScrollView, not within. When the scrollview scrolls, the button get's clipped with part of the button going along with the scrolling and the other part staying positioned.
To better describe the issue here's a video of the issue:
http://dl.dropbox.com/u/170068/ScrollTest.mov
The planned goal was to have a button sit in the top right corner of a text view but stay there when the text view scrolls. So if anyone has any thoughts on how to achieve this it would be greatly appreciated.
You should subclass NSScrollView and override "tile" method to position sub-controls of the scroll view.
- (void)tile
{
[super tile];
if (subControl)
{
NSRect subControlFrame = [subControl frame];
// adjust control position here in the scrollview coordinate space
// move controls
[subControl setFrame:subControlFrame];
}
}
I have used this way to implement a custom ScrollView with zoom control and background color selector embedded.
Overlapping views isn't recommended for non-layer-backed views. I think Interface Builder will even warn you about this. The easiest way to work around this would be to make your button layer-backed.