如何删除分段控件的外边框?我已经将分频器图像设置为我想要的但现在要按照我的应用程序的模拟我需要一个没有外边框的分段控件.
您好我想将默认的UISegmentControl字体更改为自定义字体,并将选定的段颜色更改为另一种颜色而不是更暗的颜色.
谢谢
由此

对此

编辑:方案 称为
//更改字体大小,删除阴影,所选文本和背景颜色与正常状态不同
-(void)defineSegmentControlStyle
{
//normal segment
NSDictionary *normalAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
[UIFont fontWithName:@"Rok" size:20.0],UITextAttributeFont,
[UIColor colorWithRed:75.0/255.0 green:75.0/255.0 blue:75.0/255.0 alpha:1.0], UITextAttributeTextColor,
[UIColor clearColor], UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0, 1)], UITextAttributeTextShadowOffset,
nil];//[NSDictionary dictionaryWithObject: [UIColor redColor]forKey:UITextAttributeTextColor];
[infoSegment setTitleTextAttributes:normalAttributes forState:UIControlStateNormal];
NSDictionary *selectedAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
[UIFont fontWithName:@"Rok" size:20.0],UITextAttributeFont,
[UIColor whiteColor], UITextAttributeTextColor,
[UIColor clearColor], UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0, 1)], UITextAttributeTextShadowOffset,
nil] ;//[NSDictionary dictionaryWithObject: [UIColor redColor]forKey:UITextAttributeTextColor];
[infoSegment setTitleTextAttributes:selectedAttributes forState:UIControlStateSelected];
}
Run Code Online (Sandbox Code Playgroud) 在我的应用程序中,我能够更改所选分段控件的颜色.但是为另一个索引而不是选定的索引更改颜色.我可以在索引中找到任何错误.
帮我!
我的代码如下:
if([SegmentRound selectedSegmentIndex] == 0)
{
UIColor *newSelectedTintColor2 = [UIColor colorWithRed: 98/255.0 green:156/255.0 blue:247/255.0 alpha:1.0];
[[[SegmentRound subviews] objectAtIndex:0] setTintColor:newSelectedTintColor2];
UIColor *newSelectedTintColor1 = [UIColor colorWithRed: 54/255.0 green:52/255.0 blue:48/255.0 alpha:1.0];
[[[SegmentRound subviews] objectAtIndex:1] setTintColor:newSelectedTintColor1];
UIColor *newSelectedTintColor0 = [UIColor colorWithRed: 54/255.0 green:52/255.0 blue:48/255.0 alpha:1.0];
[[[SegmentRound subviews] objectAtIndex:2] setTintColor:newSelectedTintColor0];
FLAGROUND=1;
}
if([SegmentRound selectedSegmentIndex] == 1)
{
UIColor *newSelectedTintColor1 = [UIColor colorWithRed: 98/255.0 green:156/255.0 blue:247/255.0 alpha:1.0];
[[[SegmentRound subviews] objectAtIndex:1] setTintColor:newSelectedTintColor1];
UIColor *newSelectedTintColor0 = [UIColor colorWithRed: 54/255.0 green:52/255.0 blue:48/255.0 alpha:1.0];
[[[SegmentRound subviews] objectAtIndex:0] setTintColor:newSelectedTintColor0]; …Run Code Online (Sandbox Code Playgroud) 它很容易改变UISegmentedControl的颜色.我发现各种解决方案像这样,本网站和最好的这一解决方案.但没有一个是我想要的.
我尝试创建一个简单的东西,它很容易,这是我的代码:(我使用的是iOS 4.2,而不是5.0和xcode 4.0.2)
id segment[3];
UISegmentedControl *segmentedControl;
- (id)init
{
NSArray *itens = [NSArray arrayWithObjects: @"Option 1", @"Option 2", @"Option 3", nil];
segmentedControl = [[UISegmentedControl alloc] initWithItems:itens];
[segmentedControl setFrame:CGRectMake(0, 0, 500, 30)];
[segmentedControl setSegmentedControlStyle:UISegmentedControlStyleBar];
[segmentedControl addTarget:self
action:@selector(segmentedControl:)
forControlEvents:UIControlEventAllEvents];
switch (type) {
case type1: [segmentedControl setSelectedSegmentIndex:0]; break;
case type2: [segmentedControl setSelectedSegmentIndex:1]; break;
case type3: [segmentedControl setSelectedSegmentIndex:2]; break;
}
for (int i=0; i<3; i++) {
//The most important trick to work, have to retain the …Run Code Online (Sandbox Code Playgroud) 如何为分段控制中的选定分段自定义/更改颜色?我尝试使用UISegmentedControl中可用的方法选择了段颜色.它与iOS 5及以下版本完美配合,但不适用于iOS 6.任何帮助都表示赞赏.
基本上我希望将所选分段的颜色更改为某种明亮的颜色,以便选择/未选择的段清晰可见.
我想在Swift 3中更改UISegmentedControl所选段的tintColor。我在Objective-c中搜索了很多答案。
这是我的代码:
class ViewController:UIViewController{
var segment:UISegmentedControl
override func viewDidLoad() {
super.viewDidLoad()
segment.insertSegment(withTitle: "AAA", at: 0, animated: true)
segment.insertSegment(withTitle: "BBB", at: 1, animated: true)
segment.insertSegment(withTitle: "CCC", at: 2, animated: true)
segment.addTarget(self, action: #selector(changeValue), for: .valueChanged)
segment.selectedSegmentIndex = 0
view.addSubview(segment)
}
func changeValue(sender:AnyObject) {
//I don't know how to do that change color when segment selected
//
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢!