我需要幫助我的UISegment外觀,我在我的應用程序委託中設置了一切正常。UISegmentcontrol外觀導致問題
直到我添加了這段代碼來改變我選擇的段顏色,它引起了一個問題。
我在viewDidLoad時調用了IBAction。
它應該顯示這個
,而是它證明這一點,我知道是外觀問題,但現在不知道解決它......當我評論的出現它的代碼將在第一圖片。
的appdelegate
//normal segment
[[UISegmentedControl appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIFont fontWithName:@"Rokkitt" 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] forState:UIControlStateNormal];
//selected segment
[[UISegmentedControl appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIFont fontWithName:@"Rokkitt" size:20.0],UITextAttributeFont,
[UIColor whiteColor], UITextAttributeTextColor,
[UIColor clearColor], UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0, 1)], UITextAttributeTextShadowOffset,
nil] forState:UIControlStateHighlighted];
IBAction爲呼叫
// Get number of segments
int numSegments = [infoSegment.subviews count];
// Reset segment's color (non selected color)
for(int i = 0; i < numSegments; i++) {
// reset color
[[infoSegment.subviews objectAtIndex:i] setTintColor:[UIColor colorWithRed:196.0/255.0 green:223.0/255.0 blue:155.0/255.0 alpha:1]];
}
// Sort segments from left to right
NSArray *sortedViews = [infoSegment.subviews sortedArrayUsingFunction:compareViewsByOrigin context:NULL];
// Change color of selected segment
[[sortedViews objectAtIndex:infoSegment.selectedSegmentIndex] setTintColor:[UIColor colorWithRed:51.0/255.0 green:166.0/255.0 blue:85.0/255.0 alpha:1]];
// Remove all original segments from the control
for (id view in infoSegment.subviews) {
[view removeFromSuperview];
}
// Append sorted and colored segments to the control
for (id view in sortedViews) {
[infoSegment addSubview:view];
}
是的,我做了,只是不同的顏色 – Desmond
然而,當我點擊其他部分,它會正常工作 – Desmond