主要講解利用uilabel的來做乙個簡單的toast效果。這個是看到wdlabel的實現,感覺挺好的,就
主要的思路就是繼承uilabel,然後在drawrect:(cgrect)rect裡面進行調整,以達到乙個toast的效果。
#define klabelcornerradius 9.0f
- (void)drawrect:(cgrect)rect
如何使用呢,下面來講解使用方式。直接貼出來**吧;
- (void) showmessage:(nsstring *)message
- (void) showmessage:(nsstring *)message autohide:(bool)autohide position:(cgpoint)position duration:(float)duration
if ([message length] > 20 ) else
messagelabel_.text = message;
[messagelabel_ sizetofit]; //適應一下大小
cgrect frame = messagelabel_.frame;
frame.size
.width = max(frame.size
.width, kminimummessagewidth);
frame = cgrectinset(frame, -20, -15);
messagelabel_.frame = frame;
messagelabel_.sharpcenter = position;
if (created) ];
}// start message dismissal timer
if (messagetimer_)
if (autohide)
}- (void) nixmessagelabel
if (messagelabel_)
}- (void)hidemessage:(nstimer *)timer
completion:^(bool finished) ];
}
iOS開發總結之UILabel常用屬性
ios nsstring text first nsmutableattributedstring textlabelstr nsmutableattributedstring alloc initwithstring text textlabelstr setattributes range ns...
IOS 開發日誌 UILabel相關
ios nsstring text first nsmutableattributedstring textlabelstr nsmutableattributedstring alloc initwithstring text textlabelstr setattributes range ns...
iOS開發基礎 UILabel屬性
ios nsstring text first nsmutableattributedstring textlabelstr nsmutableattributedstring alloc initwithstring text textlabelstr setattributes range ns...