gpt4 book ai didi

iphone - 如何在 iOS 中自定义 UISegmentedControl?

转载 作者:可可西里 更新时间:2023-11-01 03:44:46 27 4
gpt4 key购买 nike

我正在自定义 UISegmentedControl,但我遇到了问题。

如何在 UISegmentedControl 中应用背景图片?更改色调不能满足我的要求。

谢谢

最佳答案

////Segmented Controll
NSArray *segmentTextContent = [NSArray arrayWithObjects: @"First",@"Second",@"Third",@"Forth", nil];
segmentedControl = [[UISegmentedControl alloc] initWithItems:segmentTextContent];
segmentedControl.frame = CGRectMake(2, 5, 316, 35);

[segmentedControl addTarget:self action:@selector(segmentAction) forControlEvents:UIControlEventValueChanged];
segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
segmentedControl.enabled = true;
segmentedControl.selectedSegmentIndex = 0;

// cutomize the font size inside segmentedControl
for (id segment in [segmentedControl subviews])
{
for (id label in [segment subviews])
{
if ([label isKindOfClass:[UILabel class]])
{
[label setTextAlignment:UITextAlignmentCenter];
[label setFont:[UIFont boldSystemFontOfSize:11]];
//[label setTextColor:[UIColor greenColor]];
}
}
}

关于iphone - 如何在 iOS 中自定义 UISegmentedControl?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7089626/

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