【发布时间】:2014-02-07 23:28:06
【问题描述】:
我已经使用以下代码设置了 UISegmentedControl 的外观,
UIImage *segmentSelected = [[UIImage imageNamed:@"Segment_Unselected.png"]
resizableImageWithCapInsets:UIEdgeInsetsMake(0, 12, 0, 12)];
UIImage *segmentUnselected = [[UIImage imageNamed:@"Segment_Selected.png"]
resizableImageWithCapInsets:UIEdgeInsetsMake(0, 12, 0, 12)];
[[UISegmentedControl appearance] setBackgroundImage:segmentUnselected
forState:UIControlStateNormal
barMetrics:UIBarMetricsDefault];
[[UISegmentedControl appearance] setBackgroundImage:segmentSelected
forState:UIControlStateSelected
barMetrics:UIBarMetricsDefault];
[[UISegmentedControl appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor colorWithRed:77.0/255.0 green:45.0/255.0 blue:8.0/255.0 alpha:1],UITextAttributeTextColor,
[UIColor clearColor], UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0, 0)], UITextAttributeTextShadowOffset,
[UIFont fontWithName:@"HelveticaNeue-Bold" size:16.0], UITextAttributeFont, nil] forState:UIControlStateNormal];
[[UISegmentedControl appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor],UITextAttributeTextColor,
[UIColor clearColor], UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0, 0)], UITextAttributeTextShadowOffset,
[UIFont fontWithName:@"HelveticaNeue-Bold" size:16.0], UITextAttributeFont, nil] forState:UIControlStateSelected];
[[UISegmentedControl appearance] setDividerImage:[UIImage imageNamed:@"SegmentedControl_Divider.png"]
forLeftSegmentState:UIControlStateNormal
rightSegmentState:UIControlStateNormal
barMetrics:UIBarMetricsDefault];
我得到了完美的输出
但现在我想设置 UISegment 的默认外观,例如
那我该怎么办???
【问题讨论】:
-
@BillWoodger 我只是在实现这段代码,我做了一个我实际发现的更改,它在代码中清晰可见。这似乎是一个复制粘贴错误。我知道每个尝试使用此代码的人最终都会发现错误,但我只是想节省其他人的时间:-)
-
@BillWoodger 你是对的。我应该在这里的评论中提到这个问题。错误的图像被分配给上面的
segmentSelected和segmentUnselected变量。 -
@AdilMalik 您可以随时将其添加为自己的答案。答案比 cmets 更明显。如果您编辑问题,您可能会混淆未来的读者,他们想知道为什么答案不能反映问题(在此示例中不一定)。我建议你添加一个答案,然后我们可以删除所有这些 cmets 以保持整洁。
标签: ios iphone objective-c uisegmentedcontrol