我正在尝试更改使用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文本字段中获取文本.有人可以告诉我,由于它不起作用,我做错了什么.我得到一个NIL回归.
- (IBAction)btnMakeRec {
UIAlertController *alert= [UIAlertController
alertControllerWithTitle:@"Recipe Name?"
message:@""
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action){
UITextField *temp = alert.textFields.firstObject;
RecipeDesc.text = temp.text;
// HERE temp is Nil
RDescription = [[NSString alloc ] initWithFormat:@"%@", RecipeDesc.text];
}];
UIAlertAction* cancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
// NSLog(@"cancel btn");
[alert dismissViewControllerAnimated:YES completion:nil];
}];
[alert addAction:ok];
[alert addAction:cancel];
[alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.placeholder = @"Enter the name of the recipe";
textField.keyboardType = UIKeyboardTypeDefault;
}];
[self presentViewController:alert animated:YES …Run Code Online (Sandbox Code Playgroud) 作为UIAlertView与UIActionsheet从iOS版8.So过时,建议不要同时使用这两种classes.With老动作片的方法,我可以能够添加标签动态地的for循环的帮助.
UIActionSheet *actionSheet = [[UIActionSheet alloc]init];
actionSheet.title = @"Departure City";
actionSheet.delegate = self;
actionSheet.tag = 1;
for (int j =0 ; j<arrayDepartureList.count; j++)
{
NSString *titleString = arrayDepartureList[j];
[actionSheet addButtonWithTitle:titleString];
}
Run Code Online (Sandbox Code Playgroud)
我可以在委托方法中使用按钮索引来执行适当的操作.这样我就可以动态创建动作表.所以在UIAlertController课堂上如何实现这一点,我问这个,因为在UIAlertController课堂上我们必须添加动作处理程序及其动作块.
这是一个奇怪的。我用下面的代码制作UIAlertController:
let optionMenu = UIAlertController(title: nil, message: "Choose Option", preferredStyle: UIAlertControllerStyle.ActionSheet)
let action = UIAlertAction(title: "Action 1", style: .Default, handler: {
(alert: UIAlertAction!) -> Void in
print("Cancelled")
})
let action2 = UIAlertAction(title: "Action 2", style: .Default, handler: {
(alert: UIAlertAction!) -> Void in
print("Cancelled")
})
let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel, handler: {
(alert: UIAlertAction!) -> Void in
print("Cancelled")
})
optionMenu.addAction(cancelAction)
optionMenu.addAction(action)
optionMenu.addAction(action2)
self.presentViewController(optionMenu, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)
这就是屏幕上的样子。选项是暗淡的(我相信后视图会受到其影响)。
我能够添加此代码以使其成为纯白色,但是分离的好处消失了。
let subview = optionMenu.view.subviews.first! as UIView
let alertContentView …Run Code Online (Sandbox Code Playgroud) 我的提醒看起来像这样:
是否有可能使输入更大并在它们之间增加空间?这是我的代码中的一个片段.我尝试更改frame第二个文本字段的属性,但它没有帮助:
let alert = UIAlertController(title: title, message: message, preferredStyle: .Alert)
// Add the textfields
alert.addTextFieldWithConfigurationHandler({ (textField) -> Void in
textField.placeholder = "Vaše jméno"
})
alert.addTextFieldWithConfigurationHandler({ (textField) -> Void in
textField.placeholder = "Spole?né heslo"
var oldFrame = textField.frame
oldFrame.origin.y = 40
oldFrame.size.height = 60
textField.frame = oldFrame
})
Run Code Online (Sandbox Code Playgroud) 我在iOS中发现了一个错误,我想知道是否有解决方法.
如果您选择UITextView带有色调的颜色,并且在选中它时,您会显示一个,UIAlertController例如通过点击导航栏按钮项目,UITextView在关闭它后会丢失它的色调颜色UIAlertController.
我正在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) 我有这个代码,UILabel当它们出现在UIAlertControllers中时会改变s 的外观:
UILabel *appearanceLabel = [UILabel appearanceWhenContainedInInstancesOfClasses:@[[UIAlertController class]]];
[appearanceLabel setAppearanceFont:kFontRegular(18)];
Run Code Online (Sandbox Code Playgroud)
但这也会影响出现在UIActivityViewControllers中的UILabels .
如何排除UILabels UIActivityViewController?
我知道您可以添加文本字段,但是可以添加标签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) ios ×7
swift ×6
ios8 ×4
objective-c ×1
tvos ×1
tvos10 ×1
uiappearance ×1
uilabel ×1
uiswitch ×1
uitextfield ×1
uitextview ×1
xcode6 ×1