Skip to main content

Posts

Showing posts from 2021

Vertical Labels in iOS (using Objective-C)

View transformations are something you might wanna need to learn more about. While rethinking the iPad interface for his UTC Chart app, it occurred to mluton to use vertical labels. After a bit of research this is what he came up with. - (void)viewDidLoad { [super viewDidLoad]; NSString *string = @"Lorem Ipsum"; UIFont *font = [UIFont preferredFontForTextStyle:UIFontTextStyleHeadline]; UILabel *label = [[UILabel alloc] init]; label.font = font; label.text = string; CGSize size = [string sizeWithAttributes:@{NSFontAttributeName:font}]; label.frame = CGRectMake(40, 40, size.width, size.height); [label.layer setAnchorPoint:CGPointMake(0.0, 0.0)]; label.transform = CGAffineTransformMakeRotation((M_PI) / 2); [self.view addSubview:label]; } The frame and setAnchorPoint values can be modified to achieve desired positioning. He chose to bypass any potential autolayout/transform conflicts by creating the label progr

Globals and Swift (Language)

We’re all aware that global variables are bad and that we shouldn’t do globals. Right? Well... Sometimes you need globally available information like user interface idiom or OS version. This information is available from UIDevice and you can grab it from anywhere in your app. Testing Device Idiom and OS Version in Swift if UIDevice.currentDevice().userInterfaceIdiom == UIUserInterfaceIdiom.Phone { ... } if UIDevice.currentDevice().systemVersion.compare("8.0", options: NSStringCompareOptions.NumericSearch) != NSComparisonResult.OrderedAscending { ... } However, that’s a lot type type and isn’t easy to read either. In Objective-C we could use macros in the pre-compiled header to make application code easier to read and write.