标签: uiappearance

如何设置UITabBarItem的未选择色调,***包括系统项***(iOS7)

(注意:我看到SO上有几个类似的问题,但是它们似乎都没有解决我想要更改自定义和系统UITabBarItems的未选择外观的特定问题.)

我在iOS7工作.我有一个带有一些按钮的UITabBar.其中一些是我的按钮,一些是系统按钮.例:

UITabBarItem *searchButton = [[UITabBarItem alloc] initWithTabBarSystemItem: UITabBarSystemItemSearch    tag: navSearchItem];
UITabBarItem *bookMkButton = [[UITabBarItem alloc] initWithTabBarSystemItem: UITabBarSystemItemBookmarks tag: navBookmarksItem];
UITabBarItem *homeButton   = [[UITabBarItem alloc] initWithTitle: @"Home"     image: [self tabBarImageNamed: @"home-tab"]     tag: navHomeItem];
UITabBarItem *setingButton = [[UITabBarItem alloc] initWithTitle: @"Settings" image: [self tabBarImageNamed: @"settings-tab"] tag: navSettingsItem];

navTabBar.items = @[ searchButton, homeButton, bookMkButton, setingButton];
Run Code Online (Sandbox Code Playgroud)

我可以轻松地设置所选按钮色调,具有:

[[UITabBar appearance] setSelectedImageTintColor: MY_FAVORITE_COLOR];
Run Code Online (Sandbox Code Playgroud)

我可以将未选中的按钮文本颜色设置为白色:

[[UITabBarItem appearance] setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys: [UIColor whiteColor], UITextAttributeTextColor, nil]
                                         forState: UIControlStateNormal];
Run Code Online (Sandbox Code Playgroud)

我想要做的是将UNSELECTED按钮的图像色调颜色设置为白色.我可以很容易地设置未选择的图像,但这只适用于我的按钮.我也想为系统按钮执行此操作.也就是说,我希望我的搜索和书签按钮也可以取消选择 - 白色.

如果我尝试重新创建他们的图标来制作自定义按钮,我很确定Apple会抱怨.这些文档非常具体,我们不应该做任何与Apple的图标类似的东西. …

uitabbaritem ios uiappearance ios7

19
推荐指数
2
解决办法
9157
查看次数

在iOS 7上更改MFMailComposerViewController中的导航按钮颜色

我正在尝试更改MFMailComposerViewController中导航按钮的文本颜色,但它在iOS 6上不起作用.在iOS 6中,它与UIAppearance一起工作如下:

// Navigation button
UIBarButtonItem *barButton = [UIBarButtonItem appearance];
NSDictionary *barButtonTitleTextAttributes = @{UITextAttributeTextColor: [UIColor redColor]};
NSDictionary *disabledBarButtonTitleTextAttributes = @{UITextAttributeTextColor: [UIColor grayColor]};

[barButton setTitleTextAttributes:barButtonTitleTextAttributes forState:UIControlStateNormal];
[barButton setTitleTextAttributes:disabledBarButtonTitleTextAttributes forState:UIControlStateDisabled];
[barButton setBackgroundImage:[[UIImage imageNamed:@"btn_appearance"] stretchableImageWithLeftCapWidth:6 topCapHeight:0] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
Run Code Online (Sandbox Code Playgroud)

但这在iOS 7上不起作用,看起来总是这样: 在此输入图像描述

我也尝试tintColor在navigationBar上设置属性,但这也没有效果:

navigationBar.tintColor = [UIColor redColor];
Run Code Online (Sandbox Code Playgroud)

无论如何在iOS 7上更改MFMailComposeViewController中的导航按钮文本颜色?

uiappearance ios7 mfmailcomposeviewcontroller

19
推荐指数
2
解决办法
1万
查看次数

包含在多个类中的iOS 6外观

我在appearanceWhenContainedIn我想要在iOS 6应用程序中自定义的某些UI元素上使用该方法.我发现的问题是,如果我尝试提供多个容器类,则不会应用任何自定义,如下所示:

// Works neither for toolbar nor navbar items
[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], [UIToolbar class], nil]

// Works fine (but only for navbar items, obviously)
[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil]
Run Code Online (Sandbox Code Playgroud)

官方文档说这个方法的参数可以是多个类的nil终止列表,但在我的情况下,它永远不会按照它应该的方式工作.我在这里错过了什么吗?

xcode objective-c uiappearance ios6

18
推荐指数
1
解决办法
7961
查看次数

UISwitch setThumbTintColor导致崩溃(仅限iOS 6)?

更新:从Apple收到一封邮件,说明现在修复了错误/问题,下一个SDK版本不会出现此问题.和平!

我在AppDelegate的代码中有这个:

- (void) customizeAppearance {
    [[UISwitch appearance] setOnTintColor:[UIColor colorWithRed:0 green:175.0/255.0 blue:176.0/255.0 alpha:1.0]];
    [[UISwitch appearance] setTintColor:[UIColor colorWithRed:255.0f/255.0f green:255.0f/255.0f blue:255.0f/255.0f alpha:1.000f]];
    [[UISwitch appearance] setThumbTintColor:[UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:1.0]];
 }
Run Code Online (Sandbox Code Playgroud)

然后我打电话来 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

我也用ARC.在iOS 6中,我的应用程序一直在崩溃.我启用了NSZombie,它一直说:*** -[UIDeviceRGBColor release]: message sent to deallocated instance 0x9658eb0

现在我已经意识到上面的一个完全可重复的流程.当我在customizeAppearance中单独注释掉setThumbTintColor行时,一切正常.当我使用setThumbTintColor代替时,应用程序每次都会以完全相同的方式崩溃.

这是UISwitch/setThumbTintColor/UIColor的任何人都知道的问题吗?如果没有开关颜色,还有什么原因?

iphone uicolor uiswitch ios uiappearance

18
推荐指数
1
解决办法
3420
查看次数

UIAppearance对以编程方式创建的UILabels没有生效

我们扩展了UILabel,以便能够在我们的应用程序中为给定标签类型的所有用途应用标准字体和颜色.例如.

@interface UILabelHeadingBold : UILabel
@end
Run Code Online (Sandbox Code Playgroud)

在我们的AppDelegate中,我们应用这样的字体和颜色

[[UILabelHeadingBold appearance] setTextColor:<some color>];
[[UILabelHeadingBold appearance] setFont:<some font>];
Run Code Online (Sandbox Code Playgroud)

在我们的XIB中添加UILabel时,我们现在可以选择类型为UILabelHeadingBold的类,并且它按预期工作.标签显示正确的字体和颜色,如我们的AppDelegate中所指定.

但是,如果我们以编程方式创建标签,例如.

UILabelHeadingBold *headingLabel = [[UILabelHeadingBold alloc] initWithFrame:CGRectMake(10, 10, 100, 30)];
[self.mainView addSubview:headingLabel];
Run Code Online (Sandbox Code Playgroud)

UILabel没有应用预期的字体/颜色.我们必须手动应用这些属性.

有没有办法让UIAppearance在编程创建的UI元素上生效,还是仅在XIB中使用时才有效?

appearance ios uiappearance

17
推荐指数
3
解决办法
4523
查看次数

覆盖MFMailComposeViewController的UIAppearance属性

我正在使用UIAppearance协议在我的应用程序中设置UINavigationBar对象的背景图像.

[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"image-name"] forBarMetrics:UIBarMetricsDefault];
Run Code Online (Sandbox Code Playgroud)

我想为MFMailComposeViewController的实例覆盖它,以便显示默认样式导航栏.我尝试使用appearanceWhenContainedIn来设置它,这适用于iOS 5但不适用于iOS 6.

[[UINavigationBar appearanceWhenContainedIn:[MFMailComposeViewController class], nil] setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
Run Code Online (Sandbox Code Playgroud)

我是犯了错误还是有更好的方法来实现这个目标?

cocoa-touch objective-c ios uiappearance ios6

17
推荐指数
1
解决办法
9284
查看次数

自定义对象的UIAppearance代理

我有一个自定义对象,它继承自NSObject.这个对象做了"一些事情",其中一个是用一些UIKit对象创建一个UIView(UILabel,UIButtons ecc ecc ...).此对象具有一些属性,如:textColor,font,backgroundColor ...,用于自定义包含的UIKit对象的外观.

我想为这个对象的所有创建实例定制这个属性"一次性",我已经看了UIAppearance协议.

标准UIKit对象已经符合UIAppearance协议,但我不想在所有UILabel或UIButtons上应用该样式.我想仅将样式应用于对象实例中包含的UILabel和UIButtons.而且,我不能(我不想)使用appearanceWhenContainedIn:因为使用我的自定义对象的开发人员可能不知道它内部包含什么类型的对象.

所以,我正在研究如何使我的自定义对象符合UIAppearance协议.

它必须实现AFAIK

+ (id)appearance
Run Code Online (Sandbox Code Playgroud)

方法.此方法应返回一个代理对象,您可以在其中发送所有自定义项.但是,看一下UIKit对象的外观方法,我发现返回了一个私有对象.类_UIAppearance的对象.

所以,似乎Apple没有给我一个标准的代理对象来定制我自己的,我必须从头开始创建.是对的还是我失去了什么?

谢谢

objective-c ios uiappearance

17
推荐指数
1
解决办法
5397
查看次数

设置导航栏后退按钮图像

我想将UINavigationBar中的后退按钮设置为此图像:

在此输入图像描述

我不希望图像嵌入标准后退按钮图像,我只想要显示此图像.

通过查看我可以使用的其他问题,我知道:

[[UIBarButtonItem appearance] setBackButtonBackgroundImage:barButtonImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
Run Code Online (Sandbox Code Playgroud)

设置后退按钮的背景图像.但这导致图像被拉伸,据我所知,这个特定的图像不适合被拉伸.

有没有办法可以用我的图像替换后退按钮图像?

我支持iOS 5.0及更高版本.

uibarbuttonitem uinavigationitem ios uiappearance

17
推荐指数
3
解决办法
2万
查看次数

UIAppearance Swift 4

更新到Swift 4后,我收到编译器错误:

Static member 'appearance' cannot be used on protocol metatype 'UIAppearance.Protocol'

这是我的viewWillAppear自定义Tab Bar Controller子类中的方法,我正在设置项目文本的字体.

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)

    // compiler error on line below
    UIAppearance.appearance().setTitleTextAttributes([NSAttributedStringKey.font: font], for: UIControlState.normal)
}
Run Code Online (Sandbox Code Playgroud)

我无法解决这个问题,任何指导都将不胜感激,谢谢!

ios uiappearance swift swift4 xcode9-beta

17
推荐指数
1
解决办法
1万
查看次数

使用UIAppearance分别自定义UIBarButtonItem"Done"样式和"Plain"样式

我知道如何自定义UIBarButtonItem使用-setBackgroundImage: forState: barMetrics:,但我想使用不同的图像UIBarButtonItemStyleDoneUIBarButtonItemStylePlain.

有没有办法使用UIAppearance协议来实现这一目标?或者每次我想要一个"完成"样式按钮时我是否必须设置图像?

(我试着搞乱如下代码:

[[UIBarButtonItem appearance] setBackgroundImage:image forState:UIControlStateNormal barMetrics:UIBarButtonItemStyleDone];

但这只是用"完成"图像设置每个条形按钮.)

谢谢!

iphone customization uibarbuttonitem ios uiappearance

15
推荐指数
2
解决办法
8780
查看次数