想在运行时设置框架

时间:2015-06-01 12:25:34

标签: ios iphone frame

我正在尝试在运行时设置框架,但它没有任何效果,我使用以下代码:

int heightt=[ [ UIScreen mainScreen ] bounds ].size.height;

int weidtht=[[UIScreen mainScreen] bounds].size.width;


NSLog(@"weidth :%d   height :%d  ",weidtht,heightt);


if (weidtht==375 && heightt==667) {
    heightt=heightt*0.40;
    weidtht=weidtht*0.80;
} else {
    heightt=heightt*0.58;
    weidtht=weidtht*0.190;
}


NSLog(@"weidth :%d   height :%d  ",weidtht,heightt);
[self.myView setFrame:CGRectMake(weidtht, heightt, 198, 30)];

1 个答案:

答案 0 :(得分:1)

为什么要将weidht和height放在x和y的字段中?

然而试试这个:

CGRect frame = self.myView.frame
frame.size.origin.x = weidtht;
frame.size.origin.y = heightt;
self.myView.frame = frame;