objective-c - 在 ios 7 中的文本字段中提供 *hint* 作为 android 中的 edittext 字段

标签 objective-c ios7 uitextfield xcode5.0.1

我正在 ios7 应用程序中创建一个反馈表单,并希望在相应的 UITextField 中放置几个​​包含 提示UITextFields 作为名称,电话号码、电子邮件地址等。我正在使用 xcode 5 和 ios7 进行编程和创建应用程序,而无需使用 Storyboard。

Android 中的 hint 属性可用于编辑文本字段,但我无法在 ios 7 的 UITextField 中找到任何此类属性。

最佳答案

使用占位符文本属性。

这是一个例子:

UITextField *textField = [[UITextField alloc]initWithFrame:CGRectMake(10, 10, 100, 50)];
textField.font = [UIFont fontWithName:@"Arial" size:20];
textField.placeholder = @"Your hint here.";

如果您使用 Storyboard或 XIB,也可以在那里编辑此属性。

此外,如果您想为占位符使用自定义属性,您可以使用 attributedPlaceholder 属性:

NSAttributedString *attribString = [[NSAttributedString alloc] initWithText:@"Your hint here." attributes:@{NSFontAttributeName: [UIFont fontWithName:@"HelveticaNeue" size:16.0]}];
textField.attributedPlaceholder = attribString;

关于objective-c - 在 ios 7 中的文本字段中提供 *hint* 作为 android 中的 edittext 字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22009257/

相关文章:

ios - Xcode - UITextField 为空

iphone - 将 unsigned char 数组转换为 NSData 并返回

objective-c - setCollectionViewLayout :animated causing debug error: Snapshotting a view that has not been rendered results in an empty snapshot

ios - UITableViewController 偶尔调整 TableView 的大小

uitableview - iOS 7 : Dragging in UITableView/delaysContentTouches seems not working

ios - 我不明白为什么 TextGlowDemo 在 ios7 中不再起作用

ios - 使用数组更改 UITextField 的值不起作用

objective-c - 在 Objective-C 中合并 5 个 NSString

iphone - 通过代码从 consol 中清除 NSlog 生成的日志

objective-c - GROUP BY 与 SUM() 使用核心数据