我有我的UIBarButtonItems和我的UINavigationBar的背景图片.我正在尝试使用UIAppearance来自定义所有这些,具体如下:
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"navbar.png"] forBarMetrics:UIBarMetricsDefault];
[[UIBarButtonItem appearance] setBackgroundImage:[UIImage imageNamed:@"navbar_btn.png"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
Run Code Online (Sandbox Code Playgroud)
而且效果很好.唯一的问题是UINavigationBar上的默认后退按钮仍然使用标准的iOS背景颜色/图像.当我在[UINavigationBar外观]上设置TintColor时,它会改变颜色,但只需要一个UIColor.
是否可以设置默认导航后退按钮图像(无需手动更改每个viewcontroller)或将图像转换为UIColor?
谢谢!
更新:答案如下
显然,UIBarButtonItem有一个单独的函数用于后退定制.我必须根据navbar_btn.png为后退按钮创建另一个图像并使用以下方法设置它:
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButtonImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
Run Code Online (Sandbox Code Playgroud) 我正在使用iOS的UIAppearanceProxy来自定义我的应用程序的外观.
在大多数应用程序中,我希望navBar有一个背景图像.在应用程序的一个特定部分,我希望navBar具有不同的背景图像.
这就是我正在做的事情 application:didFinishLaunchingWithOptions:
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"navbar_bg1"]
forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearanceWhenContainedIn:[DiscoverViewController class], nil] setBackgroundImage:[UIImage imageNamed:@"navbar_bg2"] forBarMetrics:UIBarMetricsDefault];
Run Code Online (Sandbox Code Playgroud)
我想将所有外观代码保存在一个地方,而不是覆盖特定视图控制器中的navBar.
同样有用的是我的应用程序是用TabBarController构建的,其中每个选项卡控制一个NavigationController,它拥有一个子类ViewController,如上面的DiscoverViewController.
我究竟做错了什么?
我有一个包含许多视图控制器的项目,我希望它们都具有平铺背景图像的父视图.现在我能做到
[[UIView appearance] setBackgroundColor:
[UIColor colorWithPatternImage:[UIImage imageNamed:@"BackgroundPattern"]]];
Run Code Online (Sandbox Code Playgroud)
问题是,这也将设置所有其他的背景UIView子类对象(UIButtons,UILabels,等).我该怎么做才能改变UIView背景?
Xcode的5甚至没有熟悉setTitle到UITabBar,错误的是:
'UITabBar'没有可见的@interface声明选择器'setTitle:
寻找UITabBar:http://developer.apple.com/library/ios/navigation/未显示版本的任何变化.这里发生了什么?
编辑:
原始代码是:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
[[UITabBar appearance] setBackgroundImage:[[UIImage alloc]init]];
[[UITabBar appearance] setSelectionIndicatorImage:[[UIImage alloc]init]];
[[UITabBar appearance] setTitle:NSLocalizedString(@"home", nil)];
}
return self;
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试制作我的导航栏RGB(32,29,29),但当应用程序启动时(目前在Xcode 5.0.2的模拟器中工作),它呈现为RGB(42,38,38).
这是我想要的颜色: 
这就是我得到的颜色: 
一个微妙的区别,但很奇怪.这是我的AppDelegate.m中的外观代码:
application.statusBarStyle = UIStatusBarStyleLightContent;
[UINavigationBar appearance].tintColor = [UIColor whiteColor];
[UINavigationBar appearance].barStyle = UIBarStyleBlack;
[UINavigationBar appearance].barTintColor = [UIColor colorWithRed:32.0/255.0 green:29.0/255.0 blue:29.0/255.0 alpha:1.0];
[UITextField appearance].keyboardAppearance = UIKeyboardAppearanceDark;
Run Code Online (Sandbox Code Playgroud)
我尝试了删除其中一些设置的变体,看看是否正在应用色调,但到目前为止,我无法弄明白.这是怎么回事?
我正在做一些应该在iOS7和8中工作的东西,但由于某些原因它没有.我想通过外观代理自定义导航栏属性,并希望它应用于所有导航栏甚至是里面的导航栏UIPopover.
所以,第一步我做以下事情:
UINavigationBar *appearance = [UINavigationBar appearance];
appearance.barTintColor = [UIColor redColor];
appearance.titleTextAttributes = @{
NSForegroundColorAttributeName: [UIColor yellowColor]
};
Run Code Online (Sandbox Code Playgroud)
这应该使所有导航栏红色带黄色标题.适用于iOS8.主要在iOS7中工作.出于某种原因,当在UIPopoverController中呈现视图控制器时 - 它获得默认外观.
这就是我如何呈现popover(没什么特别的 - 几乎标准的示例代码):
UIViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"vc2"];
vc.title = @"View Controller 2";
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
self.popover = [[UIPopoverController alloc] initWithContentViewController:nav];
[self.popover presentPopoverFromRect:CGRectMake(100, 100, 100, 100) inView:self.view permittedArrowDirections:0 animated:YES];
Run Code Online (Sandbox Code Playgroud)
好的,所以我决定尝试appearanceWhenContainedIn明确地设置它的外观.在初始外观自定义中添加了以下代码:
appearance = [UINavigationBar appearanceWhenContainedIn:[UIPopoverController class], nil];
appearance.barTintColor = [UIColor greenColor];
appearance.titleTextAttributes = @{
NSForegroundColorAttributeName: [UIColor blueColor]
};
Run Code Online (Sandbox Code Playgroud)
现在.出于某种原因,最后一个代码不会影响任何内容.在iOS8中,UIPopoverControllers中的导航栏仍然是红色+黄色,而不是绿色+蓝色,而iOS7仍然使用默认外观.
我在这做错了什么?
以下是测试项目的链接:https: …
我试图设置UIButtonvia appearance proxy 的字体.但它似乎没有用.这是我试过的.
UIButton.appearance().titleFont = UIFont(name: FONT_NAME_DEFAULT, size:20.0)
UIButton.appearance().titleLabel?.font = UIFont(name: FONT_NAME_DEFAULT, size:20.0)
如何UIButton在iOS 8中通过外观代理设置字体?
编辑:在vaberer的链接中找到:"我很惊讶UIButton没有任何UI_APPEARANCE_SELECTOR属性,但符合UIAppearance协议."
我正在使用iOS 5 UINavigationBar的UIAppearance协议来自定义我的所有导航栏.
这是我的自定义功能:
- (void)customizeApperance
{
[[UINavigationBar appearance] setTintColor:[UIColor clearColor]];
[[UINavigationBar appearance] setAlpha:0.7];
UIImageView *titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"title.png"]];
[[UINavigationBar appearance] setTitleView:titleView];
}
Run Code Online (Sandbox Code Playgroud)
我有两个问题:
首先是颜色不是clearColor黑色.有什么建议?
标题视图根本没有出现.Ray Wenderlich通过添加:[[rootViewController navigationItem] setTitleView: [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"miniLogo.png"]]]in 来演示如何做到这一点applicationDidFinishLaunching.但问题是标题视图只会添加到根视图控制器中.我正在使用一个UINavigationController当我厌倦了替换rootViewControllerwith navigationController(我在AppDelegate中的导航控制器的名称)时,我根本看不到标题视图.我该如何解决这个问题?为什么不工作customizeApperance()?使用外观的关键不仅仅是创建一次标题视图(就像我在函数上面所做的那样)并且在所有导航栏中都是全局的吗?我怎样才能做到这一点?
iphone objective-c uinavigationbar uinavigationcontroller uiappearance
我的应用程序在不同的屏幕中显示分组的静态UITableViews.无论如何使用外观代理
[UITableView appearance]
Run Code Online (Sandbox Code Playgroud)
要么
[UITableViewCell appearance]
Run Code Online (Sandbox Code Playgroud)
自定义所选单元格的背景颜色?基本上我需要修改
cell.selectedBackgroundView.backgroundColor
Run Code Online (Sandbox Code Playgroud)
对于我的应用程序中的每个单元格,但我找不到在代理对象中设置的正确属性.
顺便说一下,我也试过了正常的方法(作为一个组静态表):
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
cell.selectedBackgroundView.backgroundColor = [UIColor yellowColor];
}
Run Code Online (Sandbox Code Playgroud)
但它不起作用.有什么建议吗?
我目前正在尝试在MPMoviePlayerViewController中自定义几个东西,但我遇到了其中一个滑块的问题.
如下所示,它具有2个滑块,一个音量滑块和一个小持续时间滑块.
通过使用以下内容: UIImage *thumbImage = [UIImage imageNamed:@"MPThumbSelected.png"];
[[UISlider appearance] setThumbImage:thumbImage forState:UIControlStateNormal];
我可以自定义每个滑块,包括音量滑块,但由于某种原因,导航栏中较小的滑块不会更新.有没有人有什么建议?任何帮助将不胜感激!谢谢!!

uiappearance ×11
ios ×8
objective-c ×7
iphone ×2
background ×1
cocoa-touch ×1
ios5.1 ×1
ios7 ×1
swift ×1
uibutton ×1
uifont ×1
uilabel ×1
uislider ×1
uitabbar ×1
uitableview ×1
xcode5 ×1