2012年2月24日 星期五
[iOS Dev] 不要套用UIBarStyleBlackTranslucent在NavigationBar上
今天用UIBarStyleBlackTranslucent在NavigationBar上, 發現整個top的位置會跑掉, 然後搜尋過後原來也有人遇到一樣的問題
Reference:
http://stackoverflow.com/questions/228319/navigation-controller-transparent-bar-style-is-not-working
2012年2月23日 星期四
[iOS Dev] 點擊狀態列捲軸往上問題 Tap statusbar scroll to top doesn't work
我有一個UITableView結果發現scroll到下面時
竟然無法點statusbar自動捲到最上面
後來發現是因為我的UITableViewCell裡有UIWebView, 所以action被搶走了
所以只要把UIWebView的scroll to top關掉, 就可以避免這個問題
Code (iOS5):
竟然無法點statusbar自動捲到最上面
後來發現是因為我的UITableViewCell裡有UIWebView, 所以action被搶走了
所以只要把UIWebView的scroll to top關掉, 就可以避免這個問題
Code (iOS5):
webView.scrollView.scrollsToTop = NO;
2012年2月17日 星期五
[iOS Dev] 更改UIKeyboard的底色為黑色
[inputTextView becomeFirstResponder]; [inputTextView setKeyboardAppearance:UIKeyboardAppearanceAlert];
原本的Default

更改keyboardAppearance 為 UIKeyboardAppearanceAlert

2012年2月10日 星期五
[iOS Dev] NSArray字串合併成NSString - How to join NSArray elements into an NSString?
Code:
Result:
Reference: http://stackoverflow.com/questions/1387440/how-to-join-nsarray-elements-into-an-nsstring
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSArray *args = [[NSArray alloc] initWithObjects:@"Apple", @"iOS", @"5.1", nil]; | |
NSLog(@"%@", [args componentsJoinedByString:@" "]); |
Result:
Apple iOS 5.1
Reference: http://stackoverflow.com/questions/1387440/how-to-join-nsarray-elements-into-an-nsstring
[iOS Dev] 關掉UIWebView的垂直拖曳反彈 Disable UIWebView "bouncing" vertically
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for (id subview in webView.subviews) | |
if ([[subview class] isSubclassOfClass: [UIScrollView class]]) | |
((UIScrollView *)subview).bounces = NO; |
2012年2月7日 星期二
[iOS Dev] Parse query string into dictionary
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (NSDictionary *)parseQueryString:(NSString *)query { | |
NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithCapacity:6]; | |
NSArray *pairs = [query componentsSeparatedByString:@"&"]; | |
for (NSString *pair in pairs) { | |
NSArray *elements = [pair componentsSeparatedByString:@"="]; | |
NSString *key = [[elements objectAtIndex:0] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; | |
NSString *val = [[elements objectAtIndex:1] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; | |
[dict setObject:val forKey:key]; | |
} | |
return dict; | |
} |
NSString *qs = @"username=hank&age=27&blog=whhnote.blogspot.com"; NSDictionary *queryParams = [self parseQueryString:qs]; NSLog(@"%@", queryParams); NSLog(@"%@", [queryParams objectForKey:@"username"]); // get username from dictSo, you will get a dictionary look like
{ age = 27; blog = "whhnote.blogspot.com"; username = hank; }
2012年2月1日 星期三
[Xcode] 設定預設文件開頭的 Organization
原本預設是 ___MyCompanyName___, 這樣新增檔案都要改一次
在Ternimal直接下此指令更改預設值
之後就不用改了
在Ternimal直接下此指令更改預設值
defaults write com.apple.Xcode PBXCustomTemplateMacroDefinitions '{ORGANIZATIONNAME="Hank's Company";}'
之後就不用改了
[iOS Dev] NSUserDefaults Save/Read/Clear 儲存/讀取/清除 速記
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 定義名稱 define key | |
#define kIsActive @"isActive" | |
#define kUserName @"userName" | |
// 讀取資料 | |
-(void)loadInfo { | |
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; | |
NSLog(@"Name : %@", [defaults stringForKey:kUserName]); | |
NSLog(@"isActive : %@", ([defaults boolForKey:kIsActive] ? @"YES" : @"NO")); | |
} | |
// 儲存資料 | |
-(void)saveInfo { | |
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; | |
NSString *userName = @"Hank"; | |
BOOL isActive = YES; | |
[defaults setObject:userName forKey:kUserName]; | |
[defaults setBool:isActive forKey:kIsActive]; | |
} | |
// 清除資料 | |
-(void)clearInfo { | |
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; | |
[defaults removeObjectForKey:kUserName]; | |
[defaults removeObjectForKey:kIsActive]; | |
} | |
// 執行 | |
- (void)viewDidLoad | |
{ | |
[super viewDidLoad]; | |
[self saveInfo]; | |
[self loadInfo]; | |
[self clearInfo]; | |
[self loadInfo]; | |
} |
訂閱:
文章 (Atom)