UIViewControllerRepresentable: Navigation Title and Bar Button Items Ignored in NavigationView

Solved! Problem and Expectation SwiftUI uses a UINavigationController under the hood. So, if I push a UIViewController onto a SwiftUI NavigationView using UIViewControllerRepresentable, then I would expect the navigation item and toolbar items of that view controller to be used by said navigation controller. As I mention above, they are ignored. Root Cause It turns … Read more

Extended UIButton border is not initially drawn

This works public class MyButton : UIButton { public MyButton() : base(UIButtonType.RoundedRect) { } public override RectangleF Frame { get { return base.Frame; } set { var temp = TranslatesAutoresizingMaskIntoConstraints; TranslatesAutoresizingMaskIntoConstraints = false; var constraints = new [] { NSLayoutConstraint.Create(this, NSLayoutAttribute.Width, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1.0f, value.Width), NSLayoutConstraint.Create(this, NSLayoutAttribute.Height, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1.0f, value.Height) }; AddConstraints(constraints); … Read more

How to figure out the font size of a UILabel when -adjustsFontSizeToFitWidth is set to YES?

I’m not sure if this is entirely accurate, but it should be pretty close, hopefully. It may not take truncated strings into account, or the height of the label, but that’s something you might be able to do manually. The method – (CGSize)sizeWithFont:(UIFont *)font minFontSize:(CGFloat)minFontSize actualFontSize:(CGFloat *)actualFontSize forWidth:(CGFloat)width lineBreakMode:(UILineBreakMode)lineBreakMode will return the text size, and … Read more

How update a label periodically on iOS (every second)? [duplicate]

The problem is that a scheduledTimer will not get called while the main thread is tracking touches. You need to schedule the timer in the main run loop. So instead of doing [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(updateLabel:) userInfo:nil repeats:YES]; use NSTimer* timer = [NSTimer timerWithTimeInterval:1.0f target:self selector:@selector(updateLabel:) userInfo:nil repeats:YES]; [[NSRunLoop mainRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];