OGeek|极客世界-中国程序员成长平台

标题: iOS UISegmentedControl 无法以编程方式定位 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 09:47
标题: iOS UISegmentedControl 无法以编程方式定位

我无法更改 UISegmentedControl 的位置。如果我这样做:

segControl2.frame = CGRectMake( segControl1.origin.x, segControl2.origin.y, segControl2.size.width, segControl2.size.height);

什么都没有真正改变,每个人都说改变控件的框架应该可以,但事实并非如此。



Best Answer-推荐答案


CGRect frame = [[UIScreen mainScreen] bounds];
UISegmentedControl *segControl = [[UISegmentedControl] initWithItems:[NSArray alloc] initWithObjects"One", @"Two", @"Three", nil];
segControl.frame = CGRectMake(frame.origin.x + 50, frame.origin.y + 50, segControl.size.width, segControl.size.height);
[view addSubview:segControl];

应该可以正常工作。

关于iOS UISegmentedControl 无法以编程方式定位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15536536/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4