我使用以下代码创建UILabel
并通过paramater传递来调用它。当我以不同的方向旋转时,我正在使用UIViewAutoSizingMask
自动调整标签。
[self.view addSubview:[self createLabel:CGRectMake(450,240,60,20):@"Ratings:"]];
[self.view addSubview:[self createLabel:CGRectMake(450,270,60,20):@"Reviews:"]];
[self.view addSubview:[self Label:CGRectMake(505,240,60,20):aRequests.ratings]];
[self.view addSubview:[self Label:CGRectMake(510,270,60,20):aRequests.reviews]];`
self.view1.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin |UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
-(UILabel*)createLabel:(CGRect)frame :(NSString*)labelTitle
{
UILabel *myLabel = [[UILabel alloc] initWithFrame:frame];
[UIFont fontWithName:@"Arial" size:13];
myLabel.textAlignment = UITextAlignmentLeft;
myLabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth;
myLabel.text = labelTitle;
[myLabel autorelease];
return myLabel;
}
在纵向视图中,它显示如下,
Ratings:3
Reviews:4
然而,当旋转到横向时,它会像这样显示。
Ratings: 3
Reviews: 4
在“评分”标签后面提供空间。我使用了所有Autoresizing面具仍然无法正常工作。
任何人都可以建议任何人发生了什么以及应该在上面的代码中做了哪些更改。我尝试了所有autoresizeingMask一切,但我仍然无法解决这个问题。
答案 0 :(得分:0)
面具互相冲突,使用:
self.view1.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleHeight;
和
myLabel.autoresizingMask = UIViewAutoresizingFlexibleRightMargin;