OS X开发:NSTextField文本输入框
2017-07-19 00:00
393 查看
摘要: NSTextField作为文本输入框用于接收用户的键盘输入。
NSTextField类解析如下:
OS X开发:NSTextField文本输入框
NSTextField组件可以接收用户的输入,和UITextField不同,其可以将用户的输入进行多行显示。示例代码如下:- (void)viewDidLoad { [super viewDidLoad]; //创建 MyTextField * textField = [[MyTextField alloc]initWithFrame:NSMakeRect(100, 200, 300, 40)]; //设置默认提示文字 textField.placeholderString = @"默认文字"; //设置背景 textField.backgroundColor = [NSColor redColor]; //设置是否渲染背景 textField.drawsBackground = YES; //设置文字颜色 textField.textColor = [NSColor blueColor]; //设置是否边框 textField.bordered = YES; //设置是否贝塞尔 textField.bezeled = YES; //设置代理 textField.delegate = self; [self.view addSubview:textField]; }
NSTextField类解析如下:
//设置默认提示文字 @property (nullable, copy) NSString *placeholderString; //富文本提示文字 @property (nullable, copy) NSAttributedString *placeholderAttributedString; //设置背景色 @property (nullable, copy) NSColor *backgroundColor; //设置是否渲染背景色 @property BOOL drawsBackground; //设置文字颜色 @property (nullable, copy) NSColor *textColor; //设置是否有边框 @property (getter=isBordered) BOOL bordered; //设置贝塞尔边框 @property (getter=isBezeled) BOOL bezeled; //设置是否可编辑 @property (getter=isEditable) BOOL editable; //设置是否可选择文字 @property (getter=isSelectable) BOOL selectable; //选择文本 - (void)selectText:(nullable id)sender; //代理 @property (nullable, assign) id<NSTextFieldDelegate> delegate; //是否允许称为第一响应 @property (readonly) BOOL acceptsFirstResponder; //设置贝塞尔风格 /* typedef NS_ENUM(NSUInteger, NSTextFieldBezelStyle) { NSTextFieldSquareBezel = 0, NSTextFieldRoundedBezel = 1 }; */ @property NSTextFieldBezelStyle bezelStyle; //子类可以重写如下方法: //即将进入编辑状态时被调用 返回值决定是否允许编辑 - (BOOL)textShouldBeginEditing:(NSText *)textObject; //即将结束编辑状态时调用 返回值决定是否允许结束编辑 - (BOOL)textShouldEndEditing:(NSText *)textObject; //已经开始编辑时调用 - (void)textDidBeginEditing:(NSNotification *)notification; //已经结束编辑时调用 - (void)textDidEndEditing:(NSNotification *)notification; //文本改变时调用 - (void)textDidChange:(NSNotification *)notification; //下面这些方法用来快捷创建NSTextField + (instancetype)labelWithString:(NSString *)stringValue; + (instancetype)wrappingLabelWithString:(NSString *)stringValue; + (instancetype)textFieldWithString:(nullable NSString *)stringValue; + (instancetype)labelWithAttributedString:(NSAttributedString *)attributedStringValue;
相关文章推荐
- OS X开发NSMenu应用详解
- os x开发之禁用菜单项
- IOS 开发 【os x 使用常识】
- OS X开发 --- 10.8之前系统 NSColor 转 CGColorRef
- OS X下开发!ios系统贪食蛇!——from cocos2d-x 3.0
- 在 Win 7 下使用 VirtualBOX 虚拟机安装 OS X 10.8 Mountain Lion 及 XCode 4.4.1 (iOS SDK5.1) 作开发
- OS X下开发!ios系统贪食蛇!——from cocos2d-x 3.0
- OS X 上使用.NET开发应用程序
- OS X 上使用.NET开发应用程序(转载)
- OS X开发:下拉菜单按钮NSPopUpButton应用
- Cocoa框架是iOS应用程序的基础,了解Cocoa框架,对开发iOS应用有很大的帮助。 1、Cocoa是什么? Cocoa是OS X和 iOS操作系统的程序的运行环境。 是什么因素使一个程序成为Co
- 黑马程序员——iOS开发从OS X开始
- OS X 下不通过Homebrew安装ASP.NET 5开发环境
- iOS开发笔记之五十九——OS X和iOS安全机制之一——签名机制
- OS X 开发:打开文件面板NSOpenPanel应用
- OS X 10.9 QT/QT Creator 开发调试环境的设置
- iOS开发笔记之六十——OS X和iOS安全机制之二——隔离机制
- 如何在OS X 10.7上开发一个简单的应用教程(一)
- 开发人员为何应该使用 Mac OS X 兼 OS X 小史---强烈转帖,写的实在太赞
- 开发人员为何应该使用 Mac OS X 兼 OS X 小史