你可以使用
UIAppearance
。
教程链接
并且看看
这个。
Here's a list of classes that support this feature, in one way or the other.
UIActivityIndicatorView
UIBarButtonItem
UIBarItem
UINavigationBar
UIPopoverController
UIProgressView
UISearchBar
UISegmentedControl
UISlider
UISwitch
UITabBar
UITabBarItem
UIToolbar
UIView
UIViewController
示例
UIActivityIndicatorView:
[[UIActivityIndicatorView appearance] setColor:[UIColor orangeColor]]
UINavigationBar:
[[UINavigationBar appearance] setTintColor:[UIColor brownColor]]
[[UINavigationBar appearanceWhenContainedIn:[MyCustomView class], nil] setTintColor:[UIColor blackColor]]
UIBarButtonItem:
[[UIBarButtonItem appearance] setTintColor:[UIColor redColor]]
[[UIBarButtonItem appearanceWhenContainedIn:[MyCustomView class], nil] setTintColor:[UIColor magentaColor]]
UIProgressView:
[[UIProgressView appearance] setProgressTintColor:[UIColor yellowColor]]
[[UIProgressView appearance] setTrackTintColor:[UIColor greenColor]]
UISegmentedControl:
UIImage *segmentSelected = [[UIImage imageNamed:@"Segment_Selected.png"]
resizableImageWithCapInsets:UIEdgeInsetsMake(0, 12, 0, 12)];
UIImage *segmentUnselected = [[UIImage imageNamed:@"Segment_Unselected.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 magentaColor],UITextAttributeTextColor,
[UIColor clearColor], UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0, 0)], UITextAttributeTextShadowOffset,
[UIFont fontWithName:@"Courier-Oblique" size:16.0], UITextAttributeFont, nil] forState:UIControlStateNormal];
[[UISegmentedControl appearance] setDividerImage:[UIImage imageNamed:@"SegmentedControl_Divider.png"]
forLeftSegmentState:UIControlStateNormal
rightSegmentState:UIControlStateNormal
barMetrics:UIBarMetricsDefault];
滑动条:
[[UISlider appearance] setMinimumTrackImage:[UIImage imageNamed:@"Slider_Background.png"]
forState:UIControlStateNormal]
[[UISlider appearance] setMaximumTrackImage:[UIImage imageNamed:@"Slider_Background.png"]
forState:UIControlStateNormal]
[[UISlider appearance] setThumbImage:[UIImage imageNamed:@"Slider_Thumb.png"]
forState:UIControlStateNormal]
UISwitch:
[[UISwitch appearance] setOnTintColor:[UIColor redColor]]
UITabBar:
[[UITabBar appearance] setTintColor:[UIColor brownColor]]
[[UITabBar appearance] setSelectedImageTintColor:[UIColor greenColor]]
UIToolBar:
[[UIToolbar appearance] setTintColor:[UIColor blueColor]]
UISearchBar:
[[UISearchBar appearance] setImage:[UIImage imageNamed:@"Search_Icon.png"]
forSearchBarIcon:UISearchBarIconSearch
state:UIControlStateNormal];
[[UISearchBar appearance] setImage:[UIImage imageNamed:@"Search_Cross.png"]
forSearchBarIcon:UISearchBarIconClear
state:UIControlStateNormal];
UIImage *searchBg = [UIImage imageNamed:@"Search_Background.png"];
searchBg = [searchBg stretchableImageWithLeftCapWidth:10 topCapHeight:10];
[[UISearchBar appearance] setBackgroundImage:searchBg];
编辑:
这取决于你。假设您应该将百分比的大小存储到NSUSerDefaults
或其他存储中。然后,通过使用上面的代码,您可以根据存储的百分比计算大小。明白了吗?