我已经创建了以编程方式创建的scrollview,它可以根据方向调整大小。但是在滚动视图上创建的UI元素是固定的,而不是改变的。现在我需要改变的UILabel,UITextView,UITextfield的大小,根据方向,我尝试了下面的代码,但它不适合我。
CGRect textfieldFrame = CGRectMake(12.0, 20.0, textView.frame.size.width-20, textView.frame.size.height-424);
//CGRect textfieldFrame = CGRectMake(12.0, 20.0, 270, 35);/* I used For fixed size
UITextField *textField = [[UITextField alloc] initWithFrame:textfieldFrame];
[textField setAutoresizesSubviews:YES];
[textField setAutoresizingMask:
UIViewAutoresizingFlexibleWidth |
UIViewAutoresizingFlexibleHeight];
textField.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
现在我必须根据每个方向的变化来调整元素的大小。如何解决这个问题?
发布于 2014-02-18 15:50:56
嘿,阿努帕玛,试试这个
UIInterfaceOrientation orientation = [UIApplication
sharedApplication].statusBarOrientation;
if(orientation == UIInterfaceOrientationLandscapeRight ||
orientation == UIInterfaceOrientationLandscapeLeft)
{
// your frame for landscape
}
else if(orientation==UIInterfaceOrientationPortrait)
{
// your frame for portrait
}
https://stackoverflow.com/questions/21846879
复制相似问题