Skip to main content

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 programmatically and setting the frame and size values myself. No questions. No ambiguity.

The above solution and content was initially published by mluton on his own website which was left to decay and domain expiration and was recovered by projTek - an AI-powered R&D project. The GitHub repo of the original author: https://github.com/mluton 

Comments

Popular posts from this blog

What is .csp extension? C++ Server Pages

C++ Server Pages C++ Server Pages (CSP) is a Web Engine for advanced Web Application Development, that uses blended Markup Language / C++ scripts ( such as HTML/C++, XML/C++, WML/C++ etc.) Similar to ASP and JSP, it provides a great easiness in creating web pages with dynamic content, as well as complex business applications. However, instead of Java, Javascript or VBscript, it uses C++ . This brings some significant advantages: Incredibly high processing efficiency. Benchmarks have shown a range of 80 to 250 times higher processing speed than ASP. The use of pure C++ allows the use of tons of libraries that are currently available. It is important to notice that the libraries written in C++ are tens or hundreds of times more than in any other language. It is widely accepted that the most skilled programmers in the IT market are the C++ ones. However, CGI, ISAPI and other frameworks where C++ applies, do not provide the web developer with facilities for efficient app...

Integrating SwiftUI into Existing AppKit Cocoa Projects: A Step-by-Step Guide

As Apple continues to push SwiftUI as the future of app development across its platforms, many developers find themselves in a position where they need to integrate this modern framework into their existing AppKit Cocoa projects. This integration can breathe new life into older applications, allowing developers to take advantage of SwiftUI's declarative syntax and powerful features while maintaining their existing codebase. In this guide, we'll walk through the process of adding SwiftUI to an existing AppKit Cocoa project, providing you with the knowledge to modernize your macOS applications.