gpt4 book ai didi

ios - 如何增加整个应用程序的字体大小?

转载 作者:搜寻专家 更新时间:2023-10-30 20:18:01 25 4
gpt4 key购买 nike

我正在开发需要更改所有控件的动态字体大小的应用程序。

enter image description here

正如您在屏幕截图中看到的,我必须根据字体大小的百分比更改字体。

例如

100%

lbl.font=[UIFont systemFontOfSize:20.0f];
lbl1.font=[UIFont systemFontOfSize:30.f];

80%

lbl.font=[UIFont systemFontOfSize:16.0f];
lbl1.font=[UIFont systemFontOfSize:24.f];

50%

lbl.font=[UIFont systemFontOfSize:10.0f];
lbl1.font=[UIFont systemFontOfSize:15.f];

最好的方法是什么?

最佳答案

您可以使用UIAppearanceTutorial link

&看看this也是。

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

示例

UIActivityIndi​​catorView:

[[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:

[[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 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];

编辑:

这取决于你。假设您应该将 Percentage 的大小存储到 NSUSerDefaults 或其他存储中。然后通过使用上面的代码,您可以根据存储的百分比计算大小。明白了吗?

关于ios - 如何增加整个应用程序的字体大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22188929/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com