但是存在一些问题.我正在制作一个iPad应用程序.这个应用程式可以旋转-横向或纵向.我将UILabel和MTLable对象放在没有IB的视图上.每当更改设备方向时,文本的宽度也会更改.这个结果不是我想要的.我的代码:#import "MTLabel.h".- (void)viewDidLoad{ [super viewDidLoad]; MTLabel *TitleFont = [[MTLabel alloc] initWithFrame:CGRectMake(255, 60, 270, 60)]; [TitleFont setFont:[UIFont fontWithName:@"Arial" size:30.0]]; TitleFont.backgroundColor = [UIColor greenColor]; TitleFont.text = @"Happy! - 1"; TitleFont.autoresizingMask = UIViewAutoresizingFlexibleTopMargin& UIViewAutoresizingFlexibleLeftMargin&UIViewAutoresizingFlexibleRightMargin; TitleFont.autoresizingMask= UIViewAutoresizingFlexibleWidth; [self.view addSubview:TitleFont]; //---------------------- UILabel *TitleFont2 = [[UILabel alloc] initWithFrame:CGRectMake(255, 120, 270, 60)]; [TitleFont2 setFont:[UIFont fontWithName:@"Arial" size:30.0]]; TitleFont2.backgroundColor = [UIColor orangeColor]; TitleFont2.text = @"Happy! - 2"; TitleFont2.autoresizingMask = UIViewAutoresizingFlexibleTopMargin& UIViewAutoresizingFlexibleLeftMargin&UIViewAutoresizingFlexibleRightMargin; TitleFont2.autoresizingMask= UIViewAutoresizingFlexibleWidth; [self.view addSubview:TitleFont2];}结果:1)人像: 2)风景图片:如果我使用UILabel类,没问题!但是我必须在MTLabel类中进行UILabel的行间距.请帮助我...谢谢.解决方案尝试一下:[TitleFont setContentMode:UIViewContentModeRedraw];I have to use MTLabel Class for line-spacing of UILabel.( refered sample code : https://github.com/Tuszy/MTLabel )But Some problems exists.I'm making a iPad App. This app is able to rotate - landscape or portrait.I put UILabel and MTLable objects on view without IB.Whenever orientation of device is changed, width of text also changed.This result is not what I want.My code : #import "MTLabel.h".- (void)viewDidLoad{ [super viewDidLoad]; MTLabel *TitleFont = [[MTLabel alloc] initWithFrame:CGRectMake(255, 60, 270, 60)]; [TitleFont setFont:[UIFont fontWithName:@"Arial" size:30.0]]; TitleFont.backgroundColor = [UIColor greenColor]; TitleFont.text = @"Happy! - 1"; TitleFont.autoresizingMask = UIViewAutoresizingFlexibleTopMargin& UIViewAutoresizingFlexibleLeftMargin&UIViewAutoresizingFlexibleRightMargin; TitleFont.autoresizingMask= UIViewAutoresizingFlexibleWidth; [self.view addSubview:TitleFont]; //---------------------- UILabel *TitleFont2 = [[UILabel alloc] initWithFrame:CGRectMake(255, 120, 270, 60)]; [TitleFont2 setFont:[UIFont fontWithName:@"Arial" size:30.0]]; TitleFont2.backgroundColor = [UIColor orangeColor]; TitleFont2.text = @"Happy! - 2"; TitleFont2.autoresizingMask = UIViewAutoresizingFlexibleTopMargin& UIViewAutoresizingFlexibleLeftMargin&UIViewAutoresizingFlexibleRightMargin; TitleFont2.autoresizingMask= UIViewAutoresizingFlexibleWidth; [self.view addSubview:TitleFont2];}Result :1) portrait image :2) landscape image :If I use UILabel class, no problem!But I have to MTLabel class for line-spacing of UILabel.Please help me... Thank you. 解决方案 try this:[TitleFont setContentMode:UIViewContentModeRedraw]; 这篇关于关于使用MTLabel旋转设备的麻烦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-14 13:04