Subview appears underneath superviews layer.border?

According to the Apple specification: It is composited above the receiver’s contents and sublayers. So, the border will always be above of all your subviews, even if you bring your subview to the front and so on. So I make a background view to fake the border. E.g.: UIView *backgroundView = [[UIView alloc] initWithFrame:CGRectMake(100, 100, … Read more

Unable to set frame correctly before viewDidAppear

viewDidLoad is called when the class is loaded however no ui elements have been initialised and therefore any attempt to reference them will be overwritten or unavaliable during the initialisation process which happens between the viewDidLoad and viewDidAppear calls. Once all ui element have been initalised and drawn viewDidAppear is called. viewDidLoad – Called after … Read more

Can I use autolayout to provide different constraints for landscape and portrait orientations?

Edit: Using the new concept of Size Classes introduced in Xcode 6, you can easily setup different constraints for specific size classes in Interface Builder. Most devices (e.g. all current iPhones) have a Compact vertical size class in landscape mode. This is a much better concept for general layout decisions than determining the device’s orientation. … Read more

Simply mask a UIView with a rectangle

Thanks to the link from MSK, this is the way I went with which works well: // Create a mask layer and the frame to determine what will be visible in the view. CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init]; CGRect maskRect = CGRectMake(0, 0, 50, 100); // Create a path with the rectangle in it. … Read more

Assign xib to the UIView in Swift

for Swift 4 extension UIView { class func loadFromNibNamed(nibNamed: String, bundle: Bundle? = nil) -> UIView? { return UINib( nibName: nibNamed, bundle: bundle ).instantiate(withOwner: nil, options: nil)[0] as? UIView } } for Swift 3 You could create an extension on UIView: extension UIView { class func loadFromNibNamed(nibNamed: String, bundle: NSBundle? = nil) -> UIView? { … Read more

How is the relation between UIView’s clipsToBounds and CALayer’s masksToBounds?

They are different names because UIView and CALayer are different and have different terminology associated with them, but they are functionally equivalent. If you disassemble clipsToBounds you will see it just calls masksToBounds (disassembly from the simulator framework, so x86): -(BOOL)[UIView(Rendering) clipsToBounds] +0 3091938a 55 pushl %ebp +1 3091938b 89e5 movl %esp,%ebp +3 3091938d e800000000 … Read more