1. UIFont 可以支持的字體預覽
?
為iPhone上到底支持哪些字體而發愁嗎???為光看字體名稱而不知道其長得 是啥樣子而發愁嗎?以下demo可以幫到你.
?
帖子地址? http://www.cocoachina.com/bbs/read.php?tid-19894.html
?
下載見附件:FontTest.zip
?
?
"Courier"
"AppleGothic"
"Arial"
"STHeiti TC"
"Hiragino Kaku Gothic ProN"
"Courier New"
"Zapfino"
"Arial Unicode MS"
"STHeiti SC"
"American Typewriter"
"Helvetica"
"Marker Felt"
"Helvetica Neue"
"DB LCD Temp"
"Verdana"
"Times New Roman"
"Georgia"
"STHeiti J"
"Arial Rounded MT Bold"
"Trebuchet MS"
"STHeiti K"
NSArray *familyNames = [UIFont familyNames]; for( NSString *familyName in familyNames ){ printf( "Family: %s \n", [familyName UTF8String] ); NSArray *fontNames = [UIFont fontNamesForFamilyName:familyName]; for( NSString *fontName in fontNames ){ printf( "\tFont: %s \n", [fontName UTF8String] ); } }
UIFont *tFont = [UIFont fontWithName:[[UIFont fontNamesForFamilyName:@"Helvetica"] objectAtIndex:N] size:17]; [textLabel setFont:tFont];
?
?
?
?
2. iPhone 彈出框代碼例子
?
這個 iPhone 彈出框代碼例子由 CocoaChina 會員 “sunmingze198” 分享,效果類似 iOS 系統自帶的 WiFi 選擇彈出框。
?
下載見附件:popUpDemo.zip
?
?
UIAlertView 這個元件并不常用,如果將UIAlertView 用作顯示普通訊息,這不是一個好的介面設計,因為彈出來的訊息是非常引人注意的,就好像 Javascript 的 alert 一樣,彈出來后整個視窗也不能操作,一定要用戶按下 "OK" 才能繼續操作,我相信各位也不喜歡到經常彈出 alert box 的網站吧,在 iPhone也是同樣道理。
那何時才使用 UIAlertView? 應該是有某些訊息無論如何也要用戶去知道,不是那些無關緊要的事,有可能是你的應用程式發生一些問題,令操作不能繼續的訊息。例如你的應用程式必須依賴網路來拿取資料,但用戶的裝置根本沒有連接網路,這時候你便需要使用UIAlertView 去提示用戶去連接網路,不然應用程式不能運作。
首先是最簡單,只顯示訊息并只有一個 "OK" 按鈕的 Message Box:
?
?
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Title" message:@"Message 1......\nMessage 2......" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert show]; [alert release];?
樣子:
?
cancelButtonTitle 是 UIAlertView 預設的按鈕,是必須設備的,但按鈕顯示的文字則可以任意更改。
而 otherButtonTitles 則可以用來增加按鈕,每加入一個 NSString 就會多一個按鈕。好像以下這樣:
?
?
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Title" message:@"Message 1......\nMessage 2......" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:@"Button 1", @"Button 2", @"Button 3", nil];?
這樣便會增加多三個按鈕,加上 Cancel Button 一共有 4 個按鈕。
樣子:
?
?
?
如果想按下按鈕后有其他動作,你需要在相對應的 Class 加上 UIAlertViewDelegate 的 protocol。
?
例如我想 UIViewController 當 UIAlertView 的代理:
?
ViewController.h
?
?
#import <UIKit/UIKit.h> @interface ViewController : UIViewController <UIAlertViewDelegate> { } @end?
在? ViewController.m ?加上以下方法:
?
?
- (void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ //Code..... }?
而 UIAlertView 的 CancelButton 的 buttonIndex 是 0,其他按鈕的 buttonIndex 則順序增加。
可以這樣判斷用戶究竟按下了那一個按鈕:
?
?
- (void)loadView { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Title" message:@"Message 1......\nMessage 2......" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:@"Button 1", @"Button 2", @"Button 3", nil]; [alert show]; [alert release]; } - (void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ switch (buttonIndex) { case 0: NSLog(@"Cancel Button Pressed"); break; case 1: NSLog(@"Button 1 Pressed"); break; case 2: NSLog(@"Button 2 Pressed"); break; case 3: NSLog(@"Button 3 Pressed"); break; default: break; } }?
?
?
?
?
?
?
?
?
?
?
?
?
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
