我将一个文件从Objective_c移植到Swift,它的配置改变了tabbar颜色:我在objective-c中使用的代码是:
UIColor* barColor=[UIColor colorWithRed:.88 green:.05 blue:.05 alpha:1];
if([self.navigationController.navigationBar respondsToSelector:@selector(barTintColor)])
{
// iOS7
self.navigationController.navigationBar.barTintColor = barColor;
}
else
{
[[UINavigationBar appearance] setTintColor:barColor];
// older
//self.navigationController.navigationBar.tintColor = barColor;
}
[super viewWillAppear:animated];
Run Code Online (Sandbox Code Playgroud)
和Swift中的相应代码是:
let barColor = UIColor(red:0.88, green:0.05, blue:0.05, alpha:1)
if UIDevice.currentDevice().systemVersion.compare("8.0", options: .NumericSearch) == .OrderedDescending
{
// iOS8+
UINavigationBar.appearance().tintColor=barColor
//UINavigationBar.appearance().translucent=false
}
else
{
self.navigationController!.navigationBar.barTintColor = barColor;
}
Run Code Online (Sandbox Code Playgroud)
然而,虽然objective-c代码确实改变了标签栏颜色,但相应的快速代码却没有受到损害,至少在模拟器上是这样.我做错了什么?
我使用以下方法在我的应用程序委托中设置 UILabel 外观:
UILabel.appearance().textColor = UIColor.white
Run Code Online (Sandbox Code Playgroud)
我还有一个自定义 UIView 子类,其中包含 UILabel 以及一些其他元素(此处省略):
@IBDesignable
class CustomView: UIView {
private let descriptionLabel = HCLabel()
override init(frame: CGRect) {
super.init(frame: frame)
setup()
}
required init?(coder: NSCoder) {
super.init(coder: coder)
}
override func awakeFromNib() {
super.awakeFromNib()
self.setup()
}
private func setup() {
self.descriptionLabel.textColor = UIColor.black
// ... other things not related to descriptionLabel
}
}
Run Code Online (Sandbox Code Playgroud)
如果我CustomView在故事板中实例化,一切都会正常工作。但是,如果我在代码中实例化它,则descriptionLabel是白色(外观颜色),而不是黑色(我设置的颜色)。这里发生了什么?我的理解是,如果我设置自定义颜色,则不会使用外观颜色。
更新
我想更改导航栏中后退按钮中的箭头和文本之间的偏移量。在我设置之前它工作得很好
UINavigationBar.appearance().standardAppearance = newAppearance
这是完整的代码:
let appearance = UINavigationBar.appearance()
let standardAppearance = UINavigationBarAppearance()
standardAppearance.configureWithOpaqueBackground()
standardAppearance.backgroundColor = someColor
standardAppearance.titleTextAttributes = [NSAttributedString.Key.foregroundColor: titleColor]
standardAppearance.largeTitleTextAttributes = [NSAttributedString.Key.foregroundColor: titleColor]
standardAppearance.shadowColor = navigationShadowColor
// if remove theses 2 line, offset code works!!!
appearance.standardAppearance = standardAppearance
appearance.scrollEdgeAppearance = standardAppearance
// code to set offset
UIBarButtonItem
.appearance()
.setBackButtonTitlePositionAdjustment(
UIOffset(horizontal: -20, vertical: 0),
for: .default)
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用iOS 5中的外观方法使用背景图像.我正在使用以下语句设置背景图像:
UIImage *portraitImage = [UIImage imageNamed:@"test_bar_portrait.png"];
UIImage *landscapeImage = [UIImage imageNamed:@"test_bar_landscape.png"];
[[UINavigationBar appearance] setBackgroundImage:portraitImage forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setBackgroundImage:landscapeImage forBarMetrics:UIBarMetricsLandscapePhone];
Run Code Online (Sandbox Code Playgroud)
当我运行应用程序时,正确的图像以纵向和横向显示,但当我旋转回肖像时,它仍然显示了横向图像.
我在这里创建了一个示例测试应用程序:http: //dl.dropbox.com/u/7834263/Appearance%20Test.zip
以及正在发生的事情的屏幕截图:



我使用的是iOS 5的UIAppearance协议使用自定义导航栏后退按钮,当看到这里.与我发现的其他方法不同,这个方法是最好的,因为它保留了默认的后退按钮动画和行为.
唯一的问题是我无法更改其大小或将其设置为不剪辑子视图.这是发生了什么:

A是预期的行为,B是默认样式,C是剪切结果.
不幸的是,它并不像将UIBarButtonItem设置为clipsToBounds = NO那么容易.
有谁知道如何解决这个问题?谢谢!
如何更改UIActivityViewController模态共享操作中使用的邮件撰写对象的导航栏的外观?

UIActivityViewController符合UIAppearance,所以我认为以下工作确实有效,但事实并非如此.导航栏保持默认蓝色.
activityVC.navigationController.navigationBar.tintColor = [UIColor greyColor];
Run Code Online (Sandbox Code Playgroud)
语境:
- (IBAction)share {
NSString *textToShare = ...;
NSURL *url = ...;
NSArray *activityItems = [[NSArray alloc] initWithObjects:textToShare,url,nil];
UIActivity *activity = [[UIActivity alloc] init];
NSArray *applicationActivities = [[NSArray alloc] initWithObjects:activity, nil];
UIActivityViewController *activityVC =
[[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:applicationActivities];
[activityVC setExcludedActivityTypes:[NSArray arrayWithObjects: UIActivityTypeMessage,UIActivityTypeCopyToPasteboard,
UIActivityTypeAssignToContact,UIActivityTypePostToWeibo, UIActivityTypePrint,UIActivityTypeSaveToCameraRoll,
nil]];
activityVC.navigationController.navigationBar.tintColor = [UIColor greyColor];
[self presentViewController:activityVC animated:YES completion:nil];
}
Run Code Online (Sandbox Code Playgroud)
如何将UINavigationBar蓝色的色调更改为灰色.
objective-c modalviewcontroller ios uiappearance uiactivityviewcontroller
我的应用程序仅支持纵向方向,但我有网页视图,其中我显示YouTube视频,当这个视频全屏播放时,我希望播放器能够进入风景.我如何仅支持视频的横向?
此外,我使用外观API在整个应用程序中设置导航栏的样式和栏按钮项.这也适用于电影播放器.如何在应用程序的其他部分中使用外观API时如何使用电影播放器的默认布局?
在定制我的应用程序时,我变得非常沮丧.我已经创建并设计了几乎整个应用程序,包括导航栏,工具栏,tabBar等,但每次MFMailComposeViewController,MFMessageComposerViewController,Twitter或Facebook共享者甚至是QuickLook View Controller都会发挥作用时,应用程序会崩溃并显示以下消息:
*** Assertion failure in -[UICGColor encodeWithCoder:].
*** Terminating app due to uncaught exception 'NSInternalInconsistencyExceptionì, reason: 'Only RGBA or White color spaces are supported in this situation.'
Run Code Online (Sandbox Code Playgroud)
我已经读到这是因为iOS 6将作曲家作为远程控制器进行管理,但我真的不知道如何解决这个问题.
因此,我不想删除邮件撰写功能或邮件撰写功能.
有没有人遇到过这个bug?
我已经有代码写了.问题是由于自定义UINavigationBars元素,UIAppearance正在使应用程序崩溃.码.
-(void)message{
if (_progressHUD){
[_progressHUD hide:YES];
}
MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init] ;
[controller setMessageComposeDelegate:self];
if([MFMessageComposeViewController canSendText])
{
controller.body = descriptionString;
controller.recipients = nil;
[self presentViewController:controller animated:YES completion:nil];
}
}
-(void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result{
[self dismissViewControllerAnimated:YES completion:nil];
}
-(void)email {
if (_progressHUD){
[_progressHUD hide:YES];
}
MFMailComposeViewController *composer …Run Code Online (Sandbox Code Playgroud) 您好我一直在试图弄清楚如何更改"填充",我认为它是UIBarButtonItem的色调,但是当我尝试使用外观或外观时,如果不能正常工作,请继续将图标显示为蓝色:
我希望它可能是白色的,当我自定义按钮本身时,我能够改变色调颜色并且它可以工作,但我想用所有按钮的外观来做.这是我做样式的代码,如果有人可以给我一个提示或提示如何做这种事情?
-(void)applyStyle {
[self styleUIButtons];
UIImage *navigationBarBackground = [[UIImage imageNamed:@"base_nav_bar" ] stretchableImageWithLeftCapWidth:0 topCapHeight:0];
[[UINavigationBar appearance]setBackgroundImage:navigationBarBackground forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance]setTitleTextAttributes:@{NSForegroundColorAttributeName: self.mainNavigationBarTextColor}];
[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil] setTitleTextAttributes:@{NSForegroundColorAttributeName: self.mainNavigationBarTextColor} forState:UIControlStateNormal];
[[UIButton appearanceWhenContainedIn:[UINavigationBar class], nil] setTitleColor:self.mainNavigationBarTextColor forState:UIControlStateNormal];
UIImage* barButtonImage = [self createSolidColorImageWithColor:[UIColor colorWithWhite:1.0 alpha:0.1] andSize:CGSizeMake(10, 10)];
[[UIBarButtonItem appearance] setBackgroundImage:barButtonImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[[UIButton appearanceWhenContainedIn:[UINavigationBar class], nil] setBackgroundImage:barButtonImage forState:UIControlStateNormal];
[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil] setTintColor:self.mainNavigationBarIconColor ];
NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:
[UIFont boldSystemFontOfSize:12], NSFontAttributeName,
[UIColor grayColor], NSForegroundColorAttributeName,
nil];
[[UISegmentedControl appearance]setTitleTextAttributes:attributes forState:UIControlStateNormal];
}
-(UIImage*)createSolidColorImageWithColor:(UIColor*)color andSize:(CGSize)size{
CGFloat scale = …Run Code Online (Sandbox Code Playgroud) 尝试使用iOS 8中的外观为所有按钮设置UIButton的字体。谷歌搜索之后,苹果似乎已将您的操作方式从操作系统更改为操作系统。在iOS 7中,这应该可以工作:
UIButton.appearance().titleLabel?.font = UIFont.inviteButtonTitleFont()
Run Code Online (Sandbox Code Playgroud)
但这似乎不再起作用。有人知道你现在怎么做吗?
uiappearance ×10
ios ×7
objective-c ×3
swift ×3
iphone ×2
cocoa-touch ×1
ibdesignable ×1
ios5 ×1
ios7 ×1
ios8 ×1
styling ×1
uibutton ×1
uiimage ×1
uilabel ×1
uitabbar ×1
uiwebview ×1
xcode ×1