[iOS] TextField Inset
實在不知道怎麼翻TextField Inset,我會把它描述為「留邊」。因為TextField沒有ContentInset這個property,所以要另找技巧來實現。
可以見到舊密碼和密碼確認的Placeholder緊靠著左側,設定過後如新密碼,向右邊位移一段距離。
實在不知道怎麼翻TextField Inset,我會把它描述為「留邊」。因為TextField沒有ContentInset這個property,所以要另找技巧來實現。
可以見到舊密碼和密碼確認的Placeholder緊靠著左側,設定過後如新密碼,向右邊位移一段距離。
在瞭解Watch App目標架構後,我們想進一步瞭解:
包含兩部分:Watch app和WatchKit extension。Watch app在Watch上運行,只包含Storyboard和Resource;WatchKit extension在iPhone上運行,與對應的iPhone App在一起。當使用者點擊Watch App後,與Watch配對的iPhone會啟動WatchKit extension,然後與Watch建立連接,於是兩者可以溝通(如獲取資料等)。
還記得把新版本垃圾管家送審,當天馬上就有奇妙的現象,因為我埋下Flurry追蹤使用者行為,查看Flurry後台,發現有好幾台裝置安裝且執行,不過僅止於「啟動」,就沒有其它行為。猜想這些裝置就是Apple審委所用的裝置,而且都分布於北美,後台還能顯示這六台是不同型號的iPhone與iPad。
可以觀察到,Apple下載後開啟垃圾管家App,就再也沒有動靜:P~
看了設備清單,Apple可真是一點都不馬乎,任何現行的裝置都要拿來審核我們的App呢!
有時候我們需要從網頁中獲得回傳資料,比如使用WebView來輸入帳密,成功登入後會回傳token,之後我們需要此token來呼叫相關API,以取得此帳密的相關資訊。
這麼做是想提高安全性,所輸入的帳密不想給App知曉,透過Web輸入後回傳字面上沒啥意義的token給App,而這個token是有效期限,一段時間過後便需要再取得一次,下次取得的token跟上次不一樣,以保護真實帳密資訊。
開發Watch App時,所要注意的角色有三個,因為Watch App無法獨自運行,需要透過iOS App來啟動與操作它,而彼此溝通的橋樑則是WatchKit Extension。我們可以很清楚地從下圖得知三個角色的關係:
使用Xcode 6.2開發Watch App時,原本的專案就是iOS App,操作順序:New->Target->Apple Watch->WatchKit App,便會同時產生WatchKit App與WatchKit Extension到專案中。WatchKit App僅含Storyboards與Resources,WatchKit Extension則含WatchKit Code與Resource。
據知未來Watch App可獨立運行,就讓我們拭目以待吧!
參考:Apple Watch开发初探。
隨著時間發展,iOS App已經變得更加複雜且龐大,使用使用 CocoaPods 管理第三方套件已成為必要之事,然而這樣還是不夠,因為我們一個專案 (Project)中不再只是一個目標 (Target),這些目標都需要同一個函式庫 (Library),但是可可豆莢 (Cocoapods)預設只為最初的那個目標,我們該怎麼下指令才能讓所有目標都能引用同一函式庫呢?
原來只要多加link_with關鍵字,後頭接上目標的名稱即可!
/** Theme: Podfile with Multiple Targets IDE: Xcode 6 Language: Objective C Date: 104/04/01 Author: HappyMan Blog: https://cg2010studio.wordpress.com/ */ source 'https://github.com/CocoaPods/Specs.git' platform :ios, '6.0' link_with 'HappyCan', 'HappyCan Today', 'HappyCan WatchKit Extension' pod 'AFNetworking' pod 'ZBarSDK' pod 'Toast', '~> 2.4' pod 'LineKit', '~> 1.4.1' pod 'MBProgressHUD' pod 'OpenSSL-Universal', '1.0.1.k’
以上範例表示我專案中有三個目標(HappyCan、HappyCan Today、HappyCan WatchKit Extension),都需要引用相同的函式庫。
曾經以為TextField和TextView裡的字只能統一屬性來顯示,從iOS 6開始它們都有了attributedText這個屬性,之後可以在字體間顯示不同的效果。
@property(nonatomic,copy) NSAttributedString *attributedText NS_AVAILABLE_IOS(6_0); // default is nil
現在我們想更進一步知道,如何將HTML的CSS轉為NSAttributedString,之後看到網頁排版漂亮,就可直接拿來套用!
這是html呈現的字樣~
此外,可參考先前介紹的文章:多重文字屬性 (Multiple Text Attribute)、LABEL裡的行距、LABEL裡的字距。
程式語言會隨著時間進化。本次專案依然會處理字串,我自己定義字串來區別用途,想知道是否包含字串 (Contains String),iOS 7以前的作法很拐彎抹角,我是查詢StackOverflow才知道,而且不是查詢一次就記起來,可見這支NSString的method有多不直覺!
iOS 8以後,就可以用「包含」這個方法:
containsString
我很自然地就使用它,在iPhone 6/6+跑都沒問題,因為一買來就是iOS 8。直到夥伴大鳥跟我說,用它iPhone 5一跑就崩潰,後來得知它手機還是iOS 7,就在想是那支method有問題。答案揭曉⋯⋯
/**
Theme: Contains String
IDE: Xcode 6
Language: Objective C
Date: 104/03/31
Author: HappyMan
Blog: https://cg2010studio.wordpress.com/
*/
/* containsString: returns YES if the target string is contained within the receiver. Same as calling rangeOfString:options: with no options, thus doing a case-sensitive, non-literal search. localizedCaseInsensitiveContainsString: is the case-insensitive variant. Note that it takes the current locale into effect as well. Locale-independent case-insensitive operation, and other needs can be achieved by calling rangeOfString:options:range:locale: directly.
*/
- (BOOL)containsString:(NSString *)aString NS_AVAILABLE(10_10, 8_0);
//--
/* These methods return length==0 if the target string is not found. So, to check for containment: ([str rangeOfString:@"target"].length > 0). Note that the length of the range returned by these methods might be different than the length of the target string, due composed characters and such.
*/
- (NSRange)rangeOfString:(NSString *)aString;
//--
NSString *str;
if ([str rangeOfString:@"HappyDay"].location != NSNotFound) {
// iOS 7以前拐彎抹角
}
if ([str containsString:@"HappyDay"]) {
// iOS 8以後可以很開心
}
把method的名稱設計得很直覺,真的是件好事呀~
參考:。
我們已經知道如何讓TextField輸入完成讓鍵盤消失,現在想要使TextView 縮回虛擬鍵盤,可以怎麼做呢?
TextView設定好delegate,並實作protocol的method如下。當鍵盤升起時,按下Done,即可讓它縮回去~
/**
Theme: Text View Done Resign First Response
IDE: Xcode 6
Language: Objective C
Date: 104/03/35
Author: HappyMan
Blog: https://cg2010studio.wordpress.com/
*/
#pragma mark -
#pragma mark - UITextFieldDelegate
-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
if ([text isEqualToString:@"\n"]) {
[textView resignFirstResponder];
// Return FALSE so that the final '\n' character doesn't get added
return NO;
}
// For any other character return TRUE so that the text gets added to the view
return YES;
}
曾經陪我們測試過許多App的平台Testflight,即將在這個月底(2/26)結束營業XD~好啦,其實是被Apple買去,整合到iTunes Connect中,未來可以去嘗試看看。
在此,我要介紹另一個發佈版本給使用者測試平台Crashlytics,它有三大功能:
過去我很常使用1和2,現在可以來嘗試3。
HappyMan・迴響