Có thể thay đổi kích thước phông chữ của các tab không?Thay đổi kích thước phông chữ của tabbaritem
Trả lời
Thực tế có một cách.
NSMutableArray *tabBarItems = [[[[[self.view subviews] objectAtIndex:1] subviews] mutableCopy] autorelease];
for (int item = 0; item < [tabBarItems count]; item++) {
for (int subview = 0; subview < [[[tabBarItems objectAtIndex:item] subviews] count]; subview++) {
for (int item = 0; item < [tabBarItems count]; item++) {
for (int subview = 0; subview < [[[tabBarItems objectAtIndex:item] subviews] count]; subview++) {
if ([[[[tabBarItems objectAtIndex:item] subviews] objectAtIndex:subview] isKindOfClass:NSClassFromString(@"UITabBarButtonLabel")])
[[[[tabBarItems objectAtIndex:item] subviews] objectAtIndex:subview] setFont:[UIFont systemFontOfSize:6.0f]];
}
}
}
}
TabBarIncreaseFonts(self.tabBarController);
void TabBarIncreaseFonts(UITabBarController* customTabBarController)
{
for(UIView* controlLevelFirst in [customTabBarController.tabBar subviews])
{
if(![controlLevelFirst isKindOfClass:NSClassFromString(@"UITabBarButton")])
continue;
for(id controlLevelSecond in [controlLevelFirst subviews])
{
[controlLevelSecond setBounds: CGRectMake(0, 0, 100, 48)];
if(![controlLevelSecond isKindOfClass:NSClassFromString(@"UITabBarButtonLabel")])
continue;
[controlLevelSecond setFont: [UIFont boldSystemFontOfSize:20]];
[controlLevelSecond setFrame: CGRectMake(0, 0, 96, 48)];
[controlLevelSecond setTextAlignment:UITextAlignmentCenter];
}
}
}
Tôi khuyên bạn nên một cách tốt hơn:
[yourTabBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor], UITextAttributeTextColor,
[NSValue valueWithUIOffset:UIOffsetMake(0,0)], UITextAttributeTextShadowOffset,
[UIFont fontWithName:@"Helvetica" size:18.0], UITextAttributeFont, nil]
forState:UIControlStateNormal];
for(UIViewController *tab in self.tabBarController.viewControllers)
{
[tab.tabBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIFont fontWithName:@"Helvetica" size:20.0], UITextAttributeFont, nil]
forState:UIControlStateNormal];
}
CẬP NHẬT: Xem câu trả lời của voghDev cho phiên bản iOS 7.0+, tránh sử dụng UITextAttributeFont không dùng nữa. – ToolmakerSteve
[rời khỏi đây vào đây để tham khảo của riêng tôi, chỉ cần một cú riff tắt câu trả lời làm việc khác. Đối với các mem đó là một bản sửa lỗi cho iOS 7, đó là ngoài vấn đề đó bằng một chút ...]
@implementation UITabBarController (Util)
- (void) fixForIos7 {
if (!IS_IOS7)
return;
UIFont *tabBarFont = [UIFont systemFontOfSize:12];
NSDictionary *titleTextAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
tabBarFont, UITextAttributeFont, nil];
for(UIViewController *tab in self.viewControllers) {
[tab.tabBarItem setTitleTextAttributes:titleTextAttributes forState:UIControlStateNormal];
}
}
@end
phương pháp còn thiếu là
#define IS_IOS7 (UIDevice.currentDevice.systemVersion.floatValue > 6.9)
đơn giản trong iOS 5.0 trở lên:
[[UITabBarItem appearance] setTitleTextAttributes:@{UITextAttributeFont:[UIFont boldSystemFontOfSize:15]} forState:UIControlStateNormal];
giải pháp tốt, nhưng sử dụng 'NSFontAttributeName' thay vì' UITextAttributeFont' – Laszlo
[Update] iOS 7.0 trở lên phiên bản của câu trả lời thoải mái @ cancer86 của:
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor], NSForegroundColorAttributeName,
[UIFont fontWithName:@"Helvetica" size:tabFontSize],
NSFontAttributeName,
nil] forState:UIControlStateNormal];
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor redColor], NSForegroundColorAttributeName,
[UIFont fontWithName:@"Helvetica" size:tabFontSize], NSFontAttributeName,
nil] forState:UIControlStateSelected];
.210
Sự thay đổi chính là UITextAttributeTextColor và UITextAttributeFont đều bị phản đối
Để áp dụng nó cho tất cả các tab (nhờ @ToolmakerSteve để chỉ ra)
for(UIViewController *tab in self.tabBarController.viewControllers)
{
[tab.tabBarItem setTitleTextAttributes: ...];
}
.. để áp dụng cho tất cả các tab, từ câu trả lời của spatil 'cho (tab UIViewController * trong self.tabBarController.viewControllers) [tab.tabBarItem setTitleTextAttributes: ...' – ToolmakerSteve
phản hồi ok được cập nhật – voghDev
chúng ta có thể có 3 phiên bản nhanh cho việc này không –
TRÊN Swift 2.0
override func viewDidLoad() {
super.viewDidLoad()
let appearance = UITabBarItem.appearance()
let attributes: [String: AnyObject] = [NSFontAttributeName:UIFont(name: "American Typewriter", size: 12)!, NSForegroundColorAttributeName: UIColor.orangeColor()]
appearance.setTitleTextAttributes(attributes, forState: .Normal)
}
Trong Swift 3.0
override func viewDidLoad() {
super.viewDidLoad()
let appearance = UITabBarItem.appearance()
let attributes: [String: AnyObject] = [NSFontAttributeName:UIFont(name: "American Typewriter", size: 12)!, NSForegroundColorAttributeName: UIColor.orange]
appearance.setTitleTextAttributes(attributes, for: .normal)
}
- 1. Highcharts Thay đổi kích thước phông chữ
- 2. Thay đổi kích thước phông chữ theo kích thước của div
- 3. Thay đổi kích thước phông chữ để điền vào UITextView?
- 4. Thay đổi "Kích thước phông chữ Windows (DPI)" trong Powershell?
- 5. Thay đổi kích thước phông chữ mã trong WebStorm IDE
- 6. Thay đổi kích thước phông chữ đầu cuối bằng C++
- 7. Chỉ thay đổi kích thước phông chữ trong SWT
- 8. Thay đổi kích thước phông chữ thành một AlertDialog
- 9. Kích thước phông chữ bất thường thay đổi
- 10. phông chữ văn bản thay đổi kích thước
- 11. Thay đổi kích thước phông chữ trong UITextView
- 12. Thay đổi kích thước phông chữ trong các ô Matlab
- 13. Kích thước phông chữ của TextView trong các thay đổi ứng dụng Android về thay đổi kích thước phông chữ từ cài đặt gốc
- 14. Thay đổi kích thước phông chữ CSS khi gia đình phông chữ rơi trở lại
- 15. Phông chữ thay đổi kích hoạt của một nhãn UILabel
- 16. Cách thay đổi kích thước phông chữ tương ứng với kích thước div
- 17. Kích thước phông chữ tiêu đề trên thanh điều hướng
- 18. Thay đổi phông chữ của JLabel
- 19. đặt kích thước phông chữ trong jquery
- 20. Cách thay đổi kích thước phông chữ của tiêu đề của tab trình biên tập Eclipse
- 21. Làm cách nào để thay đổi phông chữ và kích thước phông chữ của thẻ nhập HTML?
- 22. Tại sao tôi cần gán phông chữ của Canvas để thay đổi kích thước phông chữ trong Delphi 2009?
- 23. MessageBox.Show-- thay đổi phông chữ?
- 24. CSS, kích thước phông chữ tương đối
- 25. Kích thước phông chữ nhãn hiệu
- 26. UIButton thay đổi kích thước khi tôi thay đổi phông chữ?
- 27. Kích thước phông chữ mặc định TinyMCE
- 28. PHPExcel: Đặt kích thước phông chữ?
- 29. Kích thước phông chữ toàn cầu WPF
- 30. Tôi muốn thay đổi Kích cỡ Phông chữ NetBeans
Nó chỉ hoạt động trong iOS5.0 (hoặc mới hơn) .. – Kjuly
tốt đẹp, công trình của nó hoàn toàn tốt cho tôi .. cảm ơn – Gaurav
Những nơi nào bạn cần phải viết trên đoạn mã? Tôi cố gắng sử dụng nó sau khi [self.tabBarController setViewControllers: aControllerList hoạt hình: YES]; nhưng điều này không giúp được gì. – Abhinav