我已經設置UISegmentedControl的使用下面的代碼外觀,如何設置默認的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我只是執行這段代碼,我做了什麼變化實際上我發現,這是在代碼中清晰可見。它似乎是一個複製粘貼錯誤。我知道大家誰都會嘗試使用此代碼最終會找到的錯誤,但我只是想救其他的時間:-) – 2014-02-07 15:31:56
@BillWoodger你說得對。我應該在這裏評論這個問題。錯誤的圖像分配給上面的segmentSelected和segmentUnselected變量。 – 2014-02-07 15:34:27
@AdilMalik你可以隨時添加它作爲答案自己。答案比評論更可見。如果你編輯的問題,你可能會混淆誰不知道爲什麼的答案並不反映的問題(在這個例子不一定)未來的讀者。我建議你添加一個答案,然後我們可以刪除所有這些評論以保持整潔。 – 2014-02-07 15:40:38