尝试iOS 7做了:
[[UINavigationBar appearance] setTranslucent:NO];
Run Code Online (Sandbox Code Playgroud)
遇到了崩溃和错误:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** Illegal property type, c for appearance setter, _installAppearanceSwizzleForSetter:'
*** First throw call stack:
(0x16ad9b8 0x142e8b6 0x16ad7ab 0x72163d 0x724c34 0x169daca 0x169d8de 0x6c09 0x228ea9 0x2296e9 0x22ab5e 0x240a6c 0x240fd9 0x22c7d5 0x35a4906 0x35a4411 0x16293e5 0x162911b 0x1653b30 0x165310d 0x1652f3b 0x22a2b1 0x22c4eb 0x6f3d 0x1d0d725)
libc++abi.dylib: terminating with uncaught exception of type NSException
Run Code Online (Sandbox Code Playgroud)
其他通话工作正常:例如.
[[UINavigationBar appearance] setBarStyle: UIBarStyleBlack];
Run Code Online (Sandbox Code Playgroud)
当我在本地设置半透明时,它不会崩溃:
[self.navigationController.navigationBar setTranslucent:NO];
Run Code Online (Sandbox Code Playgroud)
我假设这是特定于iOS 7,但还没有在iOS 6中尝试相同的东西.
我试图在我的iOS7应用程序中更改UINavigationBar的外观.我正在做以下事情:
- (void)viewDidLoad
{
[super viewDidLoad];
m_sNumberToCall = @"";
UIBarButtonItem * btn = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"IconHome.png"] style:UIBarButtonItemStyleBordered target:self action:@selector(btHomeTouched:)];
self.navigationItem.leftBarButtonItem = btn;
self.navigationController.navigationBar.translucent = YES;
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"TVCNavBack.png"] forBarMetrics:UIBarMetricsDefault];
NSShadow * shadow = [[NSShadow alloc] init];
shadow.shadowColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8];
shadow.shadowOffset = CGSizeMake(0, 1);
[[UINavigationBar appearance] setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys:
[UIColor colorWithRed:245.0/255.0 green:245.0/255.0 blue:245.0/255.0 alpha:1.0],
NSForegroundColorAttributeName,
shadow,
NSShadowAttributeName,
[UIFont fontWithName:@"Helvetica-Bold" size:21.0],
NSFontAttributeName,
nil]];
}
Run Code Online (Sandbox Code Playgroud)
但是,我第一次呈现UITableViewController它是标准的iOS7导航栏,然后我按回家再次呈现它,这是我的新面貌.
任何想法为什么它第一次不起作用?
在我的应用程序中,我将全局自定义字体应用于所有标签,如下所示:
UIFont *font = [UIFont fontWithName:kMyFontName size:15.0];
[[UILabel appearance] setFont:font];
Run Code Online (Sandbox Code Playgroud)
这很好用.但是,在某些情况下,我希望能够为UILabel字符串的特定区域指定不同的字体.
所以我有这样的事情:
NSString *string = @"Foo Bar Baz";
UIFont *boldFont = [UIFont fontWithName:kMyBoldFontName size:15.0];
NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:string];
[attrString setAttributes:@{ NSFontAttributeName: boldFont } range:NSMakeRange(0, 3)];
self.myLabel.attributedText = attrString;
Run Code Online (Sandbox Code Playgroud)
然而,这似乎不起作用.我希望"Foo"是粗体,但整个字符串只有默认字体.就好像粗体字体根本没有应用,并且被UILabel外观代理上的字体集覆盖.
当我删除UILabel外观线然后它工作正常(我可以看到粗体字符串的一部分).基本上我想将自定义字体应用于标签,但是应用于字符串的不同区域的单独字体.通常这适用于属性字符串但由于某种原因设置UILabel外观字体禁用此功能(或似乎如此).
如果我删除该[[UILabel appearance] setFont:]行,那么它的工作原理:
(但是字符串的其余部分没有设置自定义字体).
所以我的问题是:有没有办法指定一个字体用作默认的应用程序范围,但仍然可以使用属性字符串部分覆盖它?
此外,如果有人可以向我解释为什么这不起作用我会很感激.
我正在编写面向iOS 5.0+平台的第一款iOS应用.我正在使用该UIAppearance协议来自定义应用程序UI.
我正在尝试更改UIBarButtonItem整个应用程序的背景.由于我UIBarButtonItem可能会根据所使用的文字或图标改变尺寸,我正试图利用UIImage resizableImageWithCapInsets:我的背景png.
我最初在Ray Wenderlich找到了我需要的代码.使用完全相同的代码,图像与上述教程中使用的图像非常接近,我得到了奇怪的结果.也许这只是我对Cocoa Touch的经验不足.
这是我正在使用的代码.
DreamsAppDelegate.m - customizeAppearance:
UIImage *btnBg = [[UIImage imageNamed:@"navBarButton-bg"]
resizableImageWithCapInsets:UIEdgeInsetsMake(0, 6, 0, 6)];
[[UIBarButtonItem appearance] setBackgroundImage:btnBg
forState:UIControlStateNormal
barMetrics:UIBarMetricsDefault];
Run Code Online (Sandbox Code Playgroud)
这是我正在尝试使用的png背景图像

这是结果(在模拟器中)

当UIAppearance规则准确应用于某个新的视图控制器时,我正在徘徊?
我制定了一些全局规则,我在我的app委托中调用它们.这样所有UIButton看起来都一样.但现在我想修改一个UIButton的外观.我已经尝试将代码删除它的背景,- (void)viewDidLoad但它不起作用 - UIAppearance规则尚未应用.在一个ViewController中,我将修改代码放在里面- (void)viewWillLayoutSubviews并且它工作得很好,但现在在另一个ViewController中它不起作用(代码是相同的).
覆盖UIAppearance规则在哪里安全?
我只是想让UITextView的键盘以暗模式出现.但是UItextView没有这样的属性.
通常,对于UITextField,您可以使用以下内容更改应用程序中的键盘:
[[UITextField appearance] setKeyboardAppearance:UIKeyboardAppearanceDark];
但是,当我尝试以下操作时,应用程序崩溃:
[[UITextView appearance] setKeyboardAppearance:UIKeyboardAppearanceDark];
所以,我的问题很简单,当我使用UITextView时,有没有办法改变键盘的外观?我希望并且想要相信Apple不会忘记为UITextView添加这样的功能.
我目前正在编制一个复杂的UIAppearance修饰符网络*,并遇到了一个问题.
我对FlatUIKit的自定义UIBarButton外观协议的使用导致MFMailComposerViewController抱怨和停止工作.
因此,有没有一种方法可以排除某些类,而不是使用UIAppearance's whenContainedIn方法来指定导致修改的类,即"何时不包含"?
*我在谈论UIAppearance用于在应用程序委托中预定义对象外观设置的协议.
题
在MFMessageComposeViewController 的文档中,apple说:
重要消息组合接口本身不可自定义,您的应用程序不得修改.
但是MFMessageComposeViewController和MFMailComposeViewController中的导航栏和barbuttonitems继承了我通过UIAppearance完成的所有样式.
我试图通过使用UIAppearance包含并将导航栏/ barbuttonitem背景图像设置为nil来恢复默认外观,但我无法弄清楚如何恢复导航栏和barbuttonitem的默认titleTextAttributes.
我试着去另一条路线并使用包容来限制我的导航控制器的样式,但似乎MFMessageComposeViewController和MFMailComposeViewController仍包含在我的navigaton控制器中,所以这没有帮助.
所以我的问题是:
1)将更改MFMessageComposeView和MFMailComposeView上的导航栏外观是应用程序商店批准的问题吗?(如果这不是问题,我可以保留自定义样式.)
2)有没有办法显示ComposeViewController,以便它不会包含在我的导航控制器中?
3)或简单地说,如何恢复barButtonItems和navigationBar的默认标题文本属性?
目前,我正在使用以下内容更改导航栏的字体AppDelegate:
[[UINavigationBar appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIFont fontWithName:@"..." size:...], NSFontAttributeName,
nil]];
Run Code Online (Sandbox Code Playgroud)
有没有办法做同样的事情来确保字符串全局大写?
我在appDelegate中使用以下代码在我的应用程序中设置我的UINavigationBar和状态栏的外观:
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
[[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor whiteColor]}];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
Run Code Online (Sandbox Code Playgroud)
此代码正确地将所有内容的外观设置为白色,除非阻止第三方模式viewController,例如来自Dropbox API或来自UIActivityViewController的Mail/Message viewController.我已经包含了一些屏幕截图来展示它们的外观.
UIActivityViewController邮件:

UIActivityViewController消息:

Dropbox API:

我试过把它放进去
[[UINavigationBar appearanceWhenContainedIn:[MFMailComposeViewController class], nil] setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor whiteColor]}];
Run Code Online (Sandbox Code Playgroud)
以及
[[UINavigationBar appearanceWhenContainedIn:[UIActivityViewController class], nil] setTintColor:[UIColor whiteColor]];
Run Code Online (Sandbox Code Playgroud)
而且没有人在工作.
uiappearance ×10
ios ×8
objective-c ×7
ios5 ×2
cocoa-touch ×1
containment ×1
ios7 ×1
uikit ×1
uilabel ×1
uitextview ×1
xcode ×1