Multiline label in UIStackView

The correct answer is here: https://stackoverflow.com/a/43110590/566360 Embed the UILabel inside a UIView (Editor -> Embed In -> View) Use constraints to fit the UILabel to the UIView (for example, trailing space, top space, and leading space to superview constraints) The UIStackView will stretch out the UIView to fit properly, and the UIView will constrain the … Read more

How to programmatically get iOS status bar height

[UIApplication sharedApplication].statusBarFrame.size.height. But since all sizes are in points, not in pixels, status bar height always equals 20. Update. Seeing this answer being considered helpful, I should elaborate. Status bar height is, indeed, equals 20.0f points except following cases: status bar has been hidden with setStatusBarHidden:withAnimation: method and its height equals 0.0f points; as @Anton … Read more

Undo/Redo for drawing in iOS

I have found a solution for this, we need to create a array of array of DrawingPaths: – (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { // Do the above code, then [m_undoArray addObject:self.currentPath]; } – (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { [m_parentUndoArray addObject:[NSArray arrayWithArray:m_undoArray]]; } and then stroke the path in DrawRect.

Resize font size to fill UITextView?

I have converted dementiazz’s answer to Swift: func updateTextFont() { if (textView.text.isEmpty || CGSizeEqualToSize(textView.bounds.size, CGSizeZero)) { return; } let textViewSize = textView.frame.size; let fixedWidth = textViewSize.width; let expectSize = textView.sizeThatFits(CGSizeMake(fixedWidth, CGFloat(MAXFLOAT))); var expectFont = textView.font; if (expectSize.height > textViewSize.height) { while (textView.sizeThatFits(CGSizeMake(fixedWidth, CGFloat(MAXFLOAT))).height > textViewSize.height) { expectFont = textView.font!.fontWithSize(textView.font!.pointSize – 1) textView.font = expectFont } … Read more

How to set a custom font for entire iOS app without specifying size

– (void)viewDidLoad { [super viewDidLoad]; [self setFontFamily:@”FagoOfficeSans-Regular” forView:self.view andSubViews:YES]; } -(void)setFontFamily:(NSString*)fontFamily forView:(UIView*)view andSubViews:(BOOL)isSubViews { if ([view isKindOfClass:[UILabel class]]) { UILabel *lbl = (UILabel *)view; [lbl setFont:[UIFont fontWithName:fontFamily size:[[lbl font] pointSize]]]; } if (isSubViews) { for (UIView *sview in view.subviews) { [self setFontFamily:fontFamily forView:sview andSubViews:YES]; } } }

Presenting a view controller modally from an action sheet’s delegate in iOS8 – iOS11

Update: As of iOS 9 SDK, UIActionSheet is deprecated, so do not expect a fix regarding this issue. It is best to start using UIAlertController when possible. The problem seems to come from Apple’s switch to using UIAlertController internally to implement the functionality of alert views and action sheets. The issue is seen mostly on … 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