gpt4 book ai didi

ios - 如何以编程方式将 UISegmentedControl 添加到容器 View

转载 作者:IT老高 更新时间:2023-10-28 11:28:50 25 4
gpt4 key购买 nike

如何定义 UISegmentedControl 的框架?我希望分段控件出现在 container view 的底部,即 UIView

最佳答案

这个是完美的,我测试过.....

UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 435)];
scroll.contentSize = CGSizeMake(320, 700);
scroll.showsHorizontalScrollIndicator = YES;

NSArray *itemArray = [NSArray arrayWithObjects: @"One", @"Two", @"Three", nil];
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:itemArray];
segmentedControl.frame = CGRectMake(35, 200, 250, 50);
segmentedControl.segmentedControlStyle = UISegmentedControlStylePlain;
[segmentedControl addTarget:self action:@selector(MySegmentControlAction:) forControlEvents: UIControlEventValueChanged];
segmentedControl.selectedSegmentIndex = 1;
[scroll addSubview:segmentedControl];
[segmentedControl release];
[self.view addSubview:scroll];

然后在你的类中添加你的方法。

- (void)MySegmentControlAction:(UISegmentedControl *)segment 
{
if(segment.selectedSegmentIndex == 0)
{
// code for the first button
}
}

对于已弃用的 UISegmentedControlStyle,您可以查看 this网址。

关于ios - 如何以编程方式将 UISegmentedControl 添加到容器 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6688160/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com