我正在尝试更改使用UIAlertController显示的警报的标题和消息字体我正在尝试使用NSAttributedStirng,但它给编译器错误,无法取代NSAttributed字符串而不是Stirng我尝试了类似于此的东西
var title_attrs = [NSFontAttributeName : CustomFonts.HELVETICA_NEUE_MEDIUM_16]
var msg_attrs = [NSFontAttributeName : CustomFonts.HELVETICA_NEUE_REGULAR_14]
var title = NSMutableAttributedString(string:"Done", attributes:title_attrs)
var msg = NSMutableAttributedString(string:"The job is done ", attributes:msg_attrs)
let alertController = UIAlertController(title: title, message: title , preferredStyle: UIAlertControllerStyle.Alert)
Run Code Online (Sandbox Code Playgroud)
有人可以指导我如何实现这一目标?
UIAlertController我这样称呼:
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"title"
message:@"msg"
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"Accept"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action) {/*...*/}
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel"
style:UIAlertActionStyleCancel
handler:^(UIAlertAction *action) {/*...*/}];
[alertController addAction:cancelAction];
[alertController addAction:okAction];
[self presentViewController:alertController animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)
我的问题是,当UIAlertController显示时,它会将导航栏的颜色从黄色更改为白色,并将系统的灯光信息按钮从蓝色更改为灰色(它看起来没有错,它看起来像是想要的“让屏幕看起来色彩较少”效果)。如果用户当时按下主页按钮,当应用程序再次从后台进入时,应用程序将保持该颜色(这会将用户带到具有白色/灰色的登录屏幕)。
这个问题有解决方法吗?
我想知道是否有人知道一种创建 UIAlertController 作为操作表的方法,该操作表看起来像 iOS 8.4 中新音乐应用程序中的操作表
\n\n我想要的是将按钮分成几组,如下图所示。正如您所看到的,“Crear una lista Genius”和“A\xc3\xb1adir a una lista...”之间有一个空格。
\n\n谢谢。
\n\n
当我定义一个UIAlertController便利初始化器时:
extension UIAlertController {
convenience init(message: String?) {
self.init(title: nil, message: message, preferredStyle: .Alert)
self.addAction(UIAlertAction(title: "OK", style: .Cancel, handler: nil))
}
}
Run Code Online (Sandbox Code Playgroud)
并在我的子类中的按钮操作中使用它UIViewController:
func buttonAction(button: UIButton) {
let alert = UIAlertController(dictionary: nil, error: nil, handler: nil)
presentViewController(alert, animated: true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud)
然后单击模拟器上的那个按钮,我收到一个警告:
尝试在取消分配时加载视图控制器的视图是不允许的,并且可能导致未定义的行为(UIAlertController)
但是,如果不使用便利初始化程序,我不会收到警告,我使用全局函数:
func UIAlertControllerWithDictionary(message: String?) -> UIAlertController {
let alert = UIAlertController(title: nil, message: message, preferredStyle: .Alert)
alert.addAction(UIAlertAction(title: "OK", style: .Cancel, handler: nil))
return alert
}
Run Code Online (Sandbox Code Playgroud)
我已将此报告给Apple作为iOS SDK错误.
在它修复之前,可以忽略警告并使用便利初始化程序吗?
我正在swift中创建一个注册对话框,其中包含3个文本字段和一个Switch,我成功添加了三个文本字段两个Alert.以下代码显示相同.
let alertController = UIAlertController(title: "Register", message: "", preferredStyle: .Alert)
let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel) { (action) in
// ...
exit(0)
}
alertController.addAction(cancelAction)
let OKAction = UIAlertAction(title: "Sign UP", style: .Default) { (action) in
// ...
let name0 = alertController.textFields![0] as UITextField
print("Text field: \(name0.text)")
let email1 = alertController.textFields![1] as UITextField
print("Text field: \(email1.text)")
let company2 = alertController.textFields![2] as UITextField
print("Text field: \(company2.text)")
}
alertController.addAction(OKAction)
alertController.addTextFieldWithConfigurationHandler { (textField) in
textField.placeholder = "Name"
textField.keyboardType = .EmailAddress
}
alertController.addTextFieldWithConfigurationHandler { …Run Code Online (Sandbox Code Playgroud) 我知道您可以添加文本字段,但是可以添加标签UIAlertController吗?
alertController.addTextFieldWithConfigurationHandler({(textField: UITextField!) in
textField.placeholder = "Hyperlink"
inputTextField = textField
inputTextField?.text="www.google.com"
})
Run Code Online (Sandbox Code Playgroud)
^^文本字段
我想显示UIAlertController上的顶部UIViewController有一个UICollectionView内.集合视图需要专注于启动,所以我preferredFocusableView按如下方式覆盖变量:
override var preferredFocusedView: UIView? {
return self.collectionView
}
Run Code Online (Sandbox Code Playgroud)
使用tvOS 9一切正常:警报控制器正常打开,我可以选择其中一个UIAlertAction显示的.
在tvOS 10 Golden Master上,打开警报控制器并滚动到另一个动作后,焦点从屏幕上消失,我无法滚动到其他操作或点击Siri遥控器的菜单按钮.该应用程序仍然卡在警报控制器中,当我尝试滚动到其他操作但屏幕上没有任何操作时,我可以听到滚动声音.我必须强制退出应用程序并重新打开它.
这是应用程序的代码.我尝试设置preferredFocusableViewto alertController.preferredFocusedView或删除集合视图的焦点方法,但没有结果.
var alertController : UIAlertController?
func showAlert() {
alertController = UIAlertController(title:"Example title", message: "Example description", preferredStyle: .Alert)
let action1 = UIAlertAction(title: "Option 1", style: .Default) { (action : UIAlertAction) -> Void in
//call to another method
}
// action2, action3, action4...
let action5 = UIAlertAction(title: "Option 5", style: .Default) { (action …Run Code Online (Sandbox Code Playgroud) 我有一个呈现的(模态)视图控制器,需要呈现一个操作表。但是当我这样做时:
UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
...
[self presentViewController:actionSheet animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)
我明白了:
Warning: Attempt to present <UIAlertController: 0x7fed4a608120> on <MyViewController: 0x7fed4d1ca520> which is already presenting (null)
Run Code Online (Sandbox Code Playgroud)
这里有解决方法吗?使用呈现的视图控制器中的警报或操作表似乎是一个非常常见的场景。
我正在用于UIAlertController一些操作。
但我不太喜欢动作组视图中的模糊视图效果(请参见下面的屏幕截图)。
我正在尝试消除这种模糊效果。我在网上做了一些研究,但找不到任何UIAlertController可以消除这种模糊效果的 API。另外,根据他们的苹果文档:
UIAlertController 类旨在按原样使用,不支持子类化。此类的视图层次结构是私有的,不得修改。
我看到 Instagram 也消除了这种模糊的视图效果:
我找到删除它的唯一方法是通过UIAlertController.
extension UIAlertController {
@discardableResult private func findAndRemoveBlurEffect(currentView: UIView) -> Bool {
for childView in currentView.subviews {
if childView is UIVisualEffectView {
childView.removeFromSuperview()
return true
} else if String(describing: type(of: childView.self)) == "_UIInterfaceActionGroupHeaderScrollView" {
// One background view is broken, we need to make sure it's white.
if let brokenBackgroundView = childView.superview {
// Set broken brackground view to a darker white …Run Code Online (Sandbox Code Playgroud) 我添加了UITextField一个UIAlertController.我想更改文本字段的高度.我试过这种方式:
let alertController = UIAlertController(title: "Comments", message: "Write your comments here", preferredStyle: UIAlertControllerStyle.alert)
alertController.addTextField { (textField : UITextField) -> Void in
var frame: CGRect = textField.frame
frame.size.height = 100
textField.frame = frame
textField.placeholder = "comment"
print(textField.frame.size.height)
}
let cancelAction = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.cancel) { (result : UIAlertAction) -> Void in
}
let okAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.default) { (result : UIAlertAction) -> Void in
}
alertController.addAction(cancelAction)
alertController.addAction(okAction)
self.present(alertController, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)
它不起作用.
ios ×8
swift ×7
ios8 ×1
objective-c ×1
tvos ×1
tvos10 ×1
uiswitch ×1
uitextfield ×1
warnings ×1
xcode ×1