我一直在使用以下代码来更改我添加的项目的文本颜色UIActionSheet.:
- (void)willPresentActionSheet:(UIActionSheet *)actionSheet {
for (UIView *subview in actionSheet.subviews) {
if ([subview isKindOfClass:[UIButton class]]) {
UIButton *button = (UIButton *)subview;
[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
}
}
}
Run Code Online (Sandbox Code Playgroud)
它工作正常iOS7,但在iOS8上面的代码中不会更改项目的文本颜色.
现在的问题是如何改变我在新增项目的文本颜色UIActionSheet使用iOS8?
附加信息:
我添加了断点,以查看上述代码中的以下行是否被执行:
UIButton *button = (UIButton *)subview;
[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
Run Code Online (Sandbox Code Playgroud)
这些行不会被执行.所以,if([subview isKindOfClass:[UIButton class]])总是false适用于所有项目actionSheet.subviews.所以我认为观点层次
UIActionSheet改变了.
在iOS 8中,似乎按钮UIAlertController(特别是动作表类型)以及UIActivityViewController从主窗口的tintColor获取颜色的按钮.
如何更改按钮文本的颜色?我试过使用这样的外观代理:
[[UIButton appearanceWhenContainedIn:[UIActivityViewController class], nil] setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
Run Code Online (Sandbox Code Playgroud)
但它没有效果.我的窗口的tintColor是白色的,因此UIActivityViewController按钮上的文本也是白色的,无法看到.更改我的窗口的tintColor解决了这个问题,但它弄乱了应用程序的其余部分.
UIActivityViewController通过底部带有白色文本的白色取消按钮查看我的屏幕截图:

同样的事情适用于UIActionSheet(是的,我知道它已被弃用)和带有actionSheet类型的UIAlertController.
如何在不更改整个应用程序的tintColor的情况下使这些窗口上的文本可读?提前致谢!
由于UIActionSheet在iOS 8中的奇怪行为,我已经将UIAlertController与UIAction一起实现为按钮.我想改变UIAlertController的整个背景.但我找不到任何办法.
甚至尝试过,
actionController.view.backgroundColor = [UIColor blackColor];
Run Code Online (Sandbox Code Playgroud)
但是没有帮助我.关于这方面的任何意见都是值得注意的.
提前致谢.
iOS7推出了一般的色彩.我认为UIAlertView也在有效范围内,但实际上tintColor看起来不适用UIAlertView.(用于可点击的按钮文字颜色)
是否可以更改警报视图的色调?如果可能,如何改变它?
这是我创建UIAlertController的代码
// Create the alert controller
var alertController = UIAlertController(title: "Are you sure you want to call \(self.number)?", message: "", preferredStyle: .Alert)
// Create the actions
var okAction = UIAlertAction(title: "Call", style: UIAlertActionStyle.Default) {
UIAlertAction in
var url:NSURL = NSURL(string: "tel://\(self.number)")!
UIApplication.sharedApplication().openURL(url)
}
var cancelAction = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel) {
UIAlertAction in
}
// Add the actions
alertController.addAction(okAction)
alertController.addAction(cancelAction)
// Present the controller
self.presentViewController(alertController, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)
我无法弄清楚如何更改取消和调用操作的文本颜色.标题文本目前为黑色,取消和呼叫按钮为白色.我正在努力让它们全黑,以提高能见度.有任何想法吗?谢谢!
这就是我UIAlertController在屏幕上创建和呈现它的方法:
private class func showAlertWithTitle(title: String, message: String) {
let alert = UIAlertController(title: title, message: message, preferredStyle: .Alert)
//alert.accessibilityLabel = "my string here" //doesnt work
let action = UIAlertAction(title: "OK", style: .Default) { action in
alert.dismissViewControllerAnimated(true, completion: nil)
}
alert.addAction(action)
UIStoryboard.topViewController()?.presentViewController(alert, animated: true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud)
这就是我在UITests下访问它的方式:
emailAlert = app.alerts["First Name"] //for title "First Name"
Run Code Online (Sandbox Code Playgroud)
但我想设置自定义标识符,并通过firstName这样访问:
emailAlert = app.alerts["firstName"]
Run Code Online (Sandbox Code Playgroud)
可能吗?
如何使用Swift更改UIAlertController的Title字体?
我不是在谈论消息颜色,我不是在谈论按钮颜色.
我在谈论标题.
我们如何在UIAlertcontroller中将归属文本设置为消息.我的尝试代码如下,但它会崩溃的应用程序.
// create Attributed text
let myAttribute = [NSForegroundColorAttributeName: UIColor(red:122.0/255, green:125.0/255, blue:131.0/255, alpha:1.0),NSFontAttributeName: Constant.flinntRegularFont(15)]
let myAttribute2 = [NSForegroundColorAttributeName: UIColor.blackColor(),NSFontAttributeName: Constant.flinntMediumFont(15)]
let myString = NSMutableAttributedString(string: "You have been unsubscribed from ", attributes: myAttribute)
let myString2 = NSMutableAttributedString(string: self.course.course_name, attributes: myAttribute2)
let myString3 = NSMutableAttributedString(string: "\n\nYour refund will be initiated within one week.", attributes: myAttribute)
let myString4 = NSMutableAttributedString(string: "\n\nFor any help call us on", attributes: myAttribute)
let myString5 = NSMutableAttributedString(string: " 079-4014 9800", attributes: myAttribute2)
let myString6 = NSMutableAttributedString(string: " between …Run Code Online (Sandbox Code Playgroud) 如何更改UIAlertAction已添加到按钮的按钮的颜色UIAlertController?
UIAlertController自定义字体不起作用.
以下代码是一个函数ShowActionSheetAsync,show ActionSheet.此时,我想改变字体ActionSheet.我尝试了几种方法,但效果不佳.有好的解决方案吗?
public Task<bool> ShowActionSheetAsync()
{
var source = new TaskCompletionSource<bool>();
var alert = new UIAlertController
{
Title = "title"
};
alert.AddAction(UIAlertAction.Create(
"button1",
UIAlertActionStyle.Default,
_ => source.SetResult(true)));
alert.AddAction(UIAlertAction.Create(
"cancel",
UIAlertActionStyle.Cancel,
_ => source.SetResult(false)));
// [Block 1]
var viewController = UIApplication.SharedApplication.KeyWindow.RootViewController;
ViewController.PresentViewController(alert, true, delegate
{
// [Block 2]
});
// [Block 3]
return source.Task;
}
Run Code Online (Sandbox Code Playgroud)
首次尝试 以下代码无法正常运行.
当我把代码放在[Block 1]或[Block 2]
当我把代码放在上面 [Block 3]
ActionSheet.从第二次起,它不起作用
UILabel.AppearanceWhenContainedIn(typeof(UIActionSheet)).Font
= UIFont.FromName(StyleResources.MediumFontName, 20);
第二次尝试 …
ios ×8
swift ×4
ios8 ×3
objective-c ×2
tintcolor ×2
c# ×1
ios7 ×1
iphone ×1
swift2.3 ×1
uialertview ×1
xamarin.ios ×1
xcode ×1