自定義UITextView控制項

2021-07-09 09:58:46 字數 1253 閱讀 3643

在專案中遇到了乙個大量使用uitextview的控制項,但是與系統自帶的uitextview又有點不一樣,需要增加提示語和字數限制,於是自己封裝了乙個簡單的自定義uitextview.

1、新建乙個類,繼承於uiview,取名為customtextview。

2、在customtextview的標頭檔案中新增如下**:

#import 

@inte***ce

customtextview : uiview

@property (nonatomic, assign) nsinteger maxlength; //可輸入字數個數

@property (nonatomic, strong) nsstring *placeholder; //提示語

@end

3、在customtextview的原始檔中新增如下**:

#define kcornerradius   5.0

#import "customtextview.h"

@inte***ce

customtextview ()

@end

@implementation

customtextview

- (id)initwithframe:(cgrect)frame

return

self;

}- (void)setmaxlength:(nsinteger)maxlength

- (void)setplaceholder:(nsstring *)placeholder

- (void)textviewdidchange:(uitextview *)textview

- (bool)textview:(uitextview *)textview shouldchangetextinrange:(nsrange)range replacementtext:(nsstring *)text

@end

1、在您需要的類中新增標頭檔案:

#import 

"customtextview.h"

2、使用customtextview,只需新增如下**:

自定義控制項 自定義鐘錶

private context mcontext 畫筆 private paint mpaint 控制項的寬 private int mwidth x方向的圓心座標 private int center 鐘錶的半徑 private int mradio 圓環的寬 private int stroke...

自定義控制項

首先是以下這幾項,attribute defaultproperty指定元件的預設屬性,toolboxdata指定當從ide工具中的 工具箱中拖動自定義控制項時為它生成的預設標記 defaultproperty text toolboxdata mycontrol runat server 上面這些...

自定義控制項

新聞管理 using system using system.collections.generic using system.linq using system.web using system.web.ui using system.web.ui.webcontrols namespace ne...