I'm working on a program for a class I'm taking and part of the program requires a UIPickerView with images in it. I have the picker up and running, but the height of the rows in the picker are still too small, causing the images (100x100) to overlap. I'm looking for a way to change the UIPickerView so that the images will fit in one row, without overlapping. Thanks
In the documentation for the UIPickerView, you have a link to the UIPickerViewDelegate protocol. There is a method that you can implement, pickerView:rowHeightForComponent:.
use this method,provide default as a delegete method.
objective-C
- (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component
{
return 40;
}
In Swift:
func pickerView(pickerView: UIPickerView, rowHeightForComponent component: Int) -> CGFloat
{
return 40
}
for more visit : real world implementation
Related
I have a subview for which I have overridden the preferredFocusedView. The subclass has a UIView called viewToFocus. I check if that view exists, if it does I focus that view, if not I return the preferredFocusedView of the parent.
Since I updated to tvOS 10 today I am getting the following error:
'preferredFocusedView' is deprecated: first deprecated in tvOS 10.0 -
Use -preferredFocusEnvironments instead.
I cant find anywhere in the documentation that explains how preferredFocusEnvironment is to be implemented. In the documentation found Supporting Focus within Your App, it says to
Override the preferredFocusedView to specify where focus should start
by default.
I tried adding the UIFocusEnvironment Protocol but I am not sure how to replace the functionality of 'preferredFocusedView' with it.
- (UIView *)preferredFocusedView {
if (self.viewToFocus) {
UIView *newView = self.viewToFocus;
self.viewToFocus = nil;
return newView;
} else {
return [super preferredFocusedView];
}
}
Thanks
You need to pass an array of views as a result of preferredFocusEnvironments call instead of just one view as it was before. This views must be ordered by the focus priority. So, if you have 3 UIButton items on your UIViewController the preferredFocusEnvironments property can be implemented the following:
- (NSArray<id<UIFocusEnvironment>> *)preferredFocusEnvironments {
return #[self.b3, self.b2, self.b1];
}
In your case you just need to return a #[newView] as a result.
I'm working with a storyboard project using size classes and autolayout. However, there are a couple instances in code where I'm adding "old school" menus and components on screen. These components are drawn correctly until the view autorotates.
I'm trying to fix the autorotation issues for controls added to UIView programmatically in iOS8. How do I determine when a UIView autorotation has completed and the view has new bounds?
There's this method which is called before rotation is completed, and view still has old size, and subviews cannot properly redraw themselves. I do not see anything along the lines of didTransition
-(void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
{
//this does not seem to work - uses old size instead of new one
[introductionView setNeedsDisplay];
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
}
The method is called viewWillTransitionToSize:withTransitionCoordinator:. The second parameter is the transition coordinator! It tells you when the rotation is over.
Here's a typical structure from my own code (in Swift, but I'm sure you can translate mentally):
override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransitionToSize(size, withTransitionCoordinator: coordinator)
coordinator.animateAlongsideTransition({
_ in
// ...
}, completion: {
_ in
// ... now the transition is over! ...
})
}
How to set scrollView document view to be pinned to top left corner? If scrollView is big enough/bigger than its content, everything is drawn from bottom to up and it not looks right. I have to override isFlipped of scrollView?
I was searching internet and overriding isFlipped to return trueis not everything. I don't want to make my documentView flipped because then I have to make changes in that class to make everything looks like I want.
I created simple NSView class as an container for elements that i want to have inside my scrollView and everything looks perfect. I hope this will help someone!
#interface FlippedView : NSView
#end
and implementation:
#implementation FlippedView
- (void)drawRect:(NSRect)dirtyRect {
[super drawRect:dirtyRect];
// Drawing code here.
}
- (BOOL) isFlipped
{
return YES;
}
#end
Swift 4 Method to invert axises :
from https://stackoverflow.com/a/40381180/5464805 thank's to Ben Leggiero :
import Cocoa
class FlippedView: NSView {
override var isFlipped: Bool { return true }
}
Then in the storyboard, set this class to the NSView below the NSClipView and it do the trick.
However it won't appear in StoryBoard so you'll have to build and run
as all we know Apple, we always need to change something for each update. Did somebody solve the moving problem for map legal link?
I tried many ways to control legal label but, just it can be hidden?
what else I can do?
thanks in advance
You need to change bottomLayoutGuide for your UIViewController. Create a class with following code:
MapLayoutGuide.h
#interface MapLayoutGuide : NSObject <UILayoutSupport>
-(id)initWithLength:(CGFloat)length;
#end
MapLayoutGuide.m
#import "MapLayoutGuide.h"
#implementation MapLayoutGuide
#synthesize length = _length;
- (id)initWithLength:(CGFloat)length
{
if (self = [super init])
{
_length = length;
}
return self;
}
#end
And then in your UIViewController, that is displaying map, add this:
-(id <UILayoutSupport>)bottomLayoutGuide
{
return [[MapLayoutGuide alloc] initWithLength:kMapViewBottomContentInset];
}
where kMapViewBottomContentInset - how much do you want to lift up Legal link. Typically size of UITabBar, if you have one.
This solution works even if you don't use AutoLayout on your view.
You can increase the height of the map so that the legal label is hidden by another view or something. I saw that some people placed a "locate me" button on top of it. I don't think that there is an easy (or legal) way to reposition or remove it.
override func viewWillLayoutSubviews() {
positionLegalMapLabel()
}
func positionLegalMapLabel() {
let legalMapLabel = self.mapView.subviews[1]
legalMapLabel.frame.origin = CGPointMake(self.mapView.bounds.size.width - legalMapLabel.frame.size.width - 7, legalMapLabel.frame.origin.y)
}
I have created an NSScrollView in interface builder that has a variable number of semi-unique NSViews that can be programmatically added and removed from it. When I add subViews to the documentView, they appear in the lower-left hand corner instead of the upper-left hand corner. I see that you can check the isFlipped bool to figure out if the view's coordinate system is flipped, but I cannot find a way to set it as flipped.
Anyone know what I'm missing?
In your NSView subclass, override isFlipped:
isFlipped
A Boolean value indicating whether the view uses a flipped coordinate system.
Declaration
var isFlipped: Bool { get }
Discussion
The default value of this property is false, which results in a non-flipped coordinate system.
[...]
If you want your view to use a flipped coordinate system, override this property and return true.
Source: isFlipped - NSView | Apple Developer Documentation
For anyone wishing to do this in Swift here's how you override in your custom class:
class FlippedView: NSView {
override var isFlipped {
get {
return true
}
}
}
The idea is that each individual view has its own way of drawing itself (for example, using human-calculated paths) that might get really wonky if you suddenly flip its coordinate plane (rasters might be fine while paths might draw upside-down, calculations might place things off-screen, Bézier control points might get twisted, etc.). So it's not settable, but subclasses can specify isFlipped because they should definitely know how the view is drawn.
Subclasses can also make it settable, but then they must expect it to change at any time.
As for code, here's Jay's answer in Swift 5:
open class FlippedView: NSView {
override var isFlipped: Bool { true }
}
Since Carl Carlson asked, here's Jay's answer in Objective-C:
Header (.h)
#interface XYZFlippedView: NSView
- (BOOL) isFlipped;
#end
Implementation (.m)
#implementation XYZFlippedView
- (BOOL) isFlipped
{
return YES;
}
#end