iOS 提示框工具

2021-07-11 04:24:16 字數 3785 閱讀 3195

//

//  toastutils.h

//  vsfa //

//  created by long on 15/7/29. 年

//#import

#import

#define showtoastattop(format, ...) \

[toastutils showattop:[nsstring stringwithformat:format, ## __va_args__]]

#define showtoast(format, ...) \

[toastutils show:[nsstring stringwithformat:format, ## __va_args__]]

#define showtoastlongattop(format, ...) \

[toastutils showlongattop:[nsstring stringwithformat:format, ## __va_args__]]

#define showtoastlong(format, ...) \

[toastutils showlong:[nsstring stringwithformat:format, ## __va_args__]]

@inte***ce

toastutils :

nsobject //

顯示提示檢視

, 預設顯示在螢幕上方,防止被軟鍵盤覆蓋,

1.5s

後自動消失

+ (void

)showattop:(

nsstring

*)message; //

顯示提示檢視

, 預設顯示在螢幕下方,

1.5s

後自動消失

+ (void

)show:(

nsstring

*)message; //

顯示提示檢視

, 預設顯示在螢幕上方,防止被軟鍵盤覆蓋

,3s後自動消失

+ (void

)showlongattop:(

nsstring

*)message; //

顯示提示檢視

, 預設顯示在螢幕下方

,3s後自動消失

+ (void

)showlong:(

nsstring

*)message;

@end

// 版權屬於原作者

(en)

// 發布**於最專業的原始碼分享**

////  toastutils.m

//  vsfa //

//  created by long on 15/7/29. 年

//#import

"toastutils.h"

#import

"zldefine.h"

@implementation

toastutils

#pragma mark -

顯示提示檢視

+ (void

)showattop:(

nsstring

*)message

+ (void

)show:(

nsstring

*)message

+ (void

)showlongattop:(

nsstring

*)message

+ (void

)showlong:(

nsstring

*)message

static

uilabel

*toastview =

nil;

+ (void

)show:(

nsstring

*)message attop:(

bool

)attop showtime:(

float

)showtime );

return;

} @synchronized

(self)

} if(

toastview

.superview

!= [

].keywindow)

//    cgfloat screenwidth = [[uiscreen mainscreen] bounds].size.width;

cgfloat

width = [

self

stringtext

:message

font:18

isheightfixed

:yes

fixedvalue:30

]; cgfloat

height = 30;

if(width >

screenwidth

- 20)

cgrect

frame =

cgrectmake

(([uiscreen

mainscreen

].bounds

.size

.width

-width)/

2, attop?[

uiscreen

mainscreen

].bounds

.size

.height

*0.15

:[uiscreen

mainscreen

].bounds

.size

.height

*0.85

, width, height);

toastview

.alpha= 1

; toastview

.text

= message;

toastview

.frame

= frame; [

uiview

animatewithduration

:showtime

animations

:^ completion

:^(bool

finished) ]; }

//根據字串長度獲取對應的寬度或者高度

+ (cgfloat

)stringtext:(

nsstring

*)text font:(

cgfloat

)font isheightfixed:(

bool

)isheightfixed fixedvalue:(

cgfloat

)fixedvalue

else

cgsize

resultsize; //

返回計算出的

size

resultsize = [text

boundingrectwithsize

:size

options

:nsstringdrawingtruncateslastvisibleline

| nsstringdrawingusesfontleading

| nsstringdrawinguseslinefragmentorigin

attributes:@

context

:nil

].size;

if(isheightfixed)

else }

@end

// 版權屬於原作者

(en)

// 發布**於最專業的原始碼分享**

iOS學習,提示框

剛開始學習ios開發,在此過程中學習到很多知識點,寫這些的目的,首先是為了給像我一樣的小白提供一些參考資料,其次是對自己所學知識的乙個總結與記錄。廢話不多說,下面開始。沒啥要匯入的,可以直接開始。感覺還是直接大串 效果好,後面會進行一定的語句分析。來!import tbviewcontroller....

關於IOS提示框

我只是把系統自帶的封裝了一下,對一些要求不是很特殊的彈框還是沒有問題的 h檔案 import inte ce alertview uiview property nonatomic,strong nsstring title property nonatomic,strong nsstring me...

高仿IOS 提示框

乙個簡單的仿ios 對話方塊,感覺很好用 記錄下來 往後可以直接轉移到別的專案中使用。先來看下效果圖 效果簡單明瞭,感覺ios 的對話方塊就要比安卓原生的好看一些,下面附上 public class alertdialog extends dialog public alertdialog cont...