跳到主要內容

發表文章

目前顯示的是有「iOS」標籤的文章

[iOS] Objective-c 比較 兩個 日期 NSDate

// 感覺應該是用排序的邏輯,desc:前面的比較大 // true: date1 大於 date2 BOOL result = [date1 compare:date2] == NSOrderedDescending; // true: date1 小於 date2 BOOL result = [date1 compare:date2] == NSOrderedAscending; // true: date1 等於 date2 BOOL result = [date1 compare:date2] == NSOrderedSame; // true: date1 大於等於 date2 BOOL result = [date1 compare:date2] == NSOrderedDescending || [date1 compare:date2] == NSOrderedSame;

[iOS] Universal Links - 待處理

  問題描述︰ 原URL可以在iPhone中直接打開APP 但在iPad中卻會打開Safari再打開AppStore,而沒有直接打開APP   看了該URL的網頁源始碼後發現他使用了 browser-deeplink 但卻只會打開AppStore   HTML裡面寫法類似 這裡 寫的問題 但用Schema似乎會有問題,解決辦法應該是用通用鏈接,如下 iOS9 Universal Links (通用鏈接)   未完待續…

[iOS] build universal library

1.「Product」->「Scheme」->「Edit Scheme」,切到「Run」分頁,將「Build Configuration」切換為「Release」。 2a. 分別build出simulator lib and iphone lib,再執行合併程式 lipo -create $(PATH_TO_libMZKit-iphonesimulator.a) $(PATH_TO_libMZKit-iphoneos.a) -output libMZKit.a 2a. Add Run Script # define output folder environment variable UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal Step 1. Build Device and Simulator versions xcodebuild -target TargetName ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphoneos BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" xcodebuild -target TargetName ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphonesimulator BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" make sure the output directory exists mkdir -p "${UNIVERSAL_OUTPUTFOLDER}" Step 2. Create universal binary file using lipolipo -create -output "${UNIVERSAL_OUTPUTFOLDER}/lib${PROJECT_NAME}.a" "${BUILD_DIR}/${CONFIG...

[iOS] Enum

Objective-C //NS_ENUM,定義狀態等普通枚舉 typedef NS_ENUM(NSUInteger, TTGState) { TTGStateOK = 0, TTGStateError, TTGStateUnknow }; //NS_OPTIONS,定義選項 typedef NS_OPTIONS(NSUInteger, TTGDirection) { TTGDirectionNone = 0, TTGDirectionTop = 1 << 0, TTGDirectionLeft = 1 << 1, TTGDirectionRight = 1 << 2, TTGDirectionBottom = 1 << 3 }; 參考 http://blog.csdn.net/annkie/article/details/9877643 Swift //簡易定義:首字母大寫 enum Color { case blue case red case green case gray case white case black } //複雜定義 enum ColorWithDesc:String { case blue = "藍色" case red = "紅色" case green = "綠色" case gray = "灰色" case white = "白色" case black = "黑色" } 參考 http://www.99ios.com/index.php/archives/3153/

[iOS] 產生iOS Documents - 使用Doxygen

使用Doxygen: 安裝 from: http://www.stack.nl/~dimitri/doxygen/download.html If you have GIT installed, you should do the following to get the initial copy of the repository: git clone https://github.com/doxygen/doxygen.git cd doxygen After that you can use mkdir build cd build cmake -G "Unix Makefiles" .. make To force a fresh build after an earlier check-out simple remove the build directory and redo the steps above. After the binaries have been built, you can use make install to install them. 使用 1 產生設定檔 doxygen -g ProjectNameConfig 2 修改設定 PROJECT_NAME = OpenCV 2.4.9 # 改成自己要的專案名字 PROJECT_NUMBER = 1.0 # 專案的版本 OUTPUT_DIRECTORY = ../docs/OpenCV2.4.9 # 輸出的位置 INPUT = /usr/local/Cellar/opencv/2.4.9 # 讀取的位置 CREATE_SUBDIRS = YES OUTPUT_LANGUAGE = Chinese-Traditional FULL_PATH_NAMES = NO EXTRACT_STATIC = YES FILE_PATTERNS = *.h *.m *.swift #讀進的副檔名, 不需要逗號 RECURSIVE = YES REFERENCED_BY_RELATION = YES REFERENCES_RELATION = YES INLINE_SOURCE = YES EXTRACT_ALL = YES 3 支援繪圖 安裝Graph...

[iOS] 取得sim卡資訊

CTTelephonyNetworkInfo *networkInfo = [CTTelephonyNetworkInfo new]; CTCarrier *carrier = [networkInfo subscriberCellularProvider]; //detect sim card status [networkInfo setSubscriberCellularProviderDidUpdateNotifier:^(CTCarrier* carrier) { NSString *countryCode = carrier.mobileCountryCode; NSString *networkCode = carrier.mobileNetworkCode; }];

[IOS] 中文字串比大小

//程式碼 func compartStringByUnicode(string1 string1: String, string2: String, asc: Bool, index: Int)->Bool{ MyVariables.logger.debug("===============> index=\(index), asc=\(asc)") let string1LengthEnough = string1.length > index let string2LengthEnough = string2.length > index if string1LengthEnough && string2LengthEnough { let targetChar1 = string1.characters.map { String($0) }[index] let targetChar2 = string2.characters.map { String($0) }[index] for u1 in targetChar1.utf16 { for u2 in targetChar2.utf16 { if u1 == u2 { return compartStringByUnicode(string1: string1, string2: string2, asc: asc, index: (index+1)) }else{ MyVariables.logger.debug("\(targetChar1) (\(u1), \(targetChar2) (\(u2)) ==> \(u1 < u2)") if asc { ...

[iOS] TextView Attributes 設定 字型 樣式

TextView Attributes 設定 字型 樣式                    var noteContent = "" noteContent += "條碼使用時機\n" noteContent += "1、結帳時出示「手機條碼」累計消費\n" noteContent += "2、出示「消費折抵/贈獎兌換條碼」使用電子贈品禮券或兌換卡友禮\n\n" noteContent += "加入會員好處\n" noteContent += "1、享有停車優惠\n" noteContent += "2、省下周慶時排隊換禮券的時間\n" noteContent += "3、卡友周慶可獨享購物禮遇\n" let optimumTextViewFontSize: CGFloat = 14.0 let myAttribute = [ NSForegroundColorAttributeName: UIColor.whiteColor(), NSFontAttributeName: UIFont.systemFontOfSize(optimumTextViewFontSize) ] let myString = NSMutableAttributedString(string: noteContent, attributes: myAttribute ) let myAttribute2 = [ NSForegroundColorAttributeName: UIColor(hexString: "#E7B3B0")!, NSFontAttributeName: UIFont.boldSystemFontOfSize(optimumTextViewFontSize + 8), NSUnderlineStyleAttributeName: 1 ] let myString2 = NSMutableAttributedString(string: "現在立即加入,還可獲得100點\n", attributes:...

[iOS] 動態 的 UITableViewCell Height

動態 的 UITableViewCell Height var heightsCache: Dictionary = [:] var cellDefaultHeight: CGFloat! override func viewDidLoad() { self.tableView.dataSource = self self.tableView.delegate = self let scale = UISizeUtils.getScaleFromPlus(self.view) // height = 621 self.cellDefaultHeight = 621.0 * scale tableView.rowHeight = UITableViewAutomaticDimension tableView.estimatedRowHeight = self.cellDefaultHeight ... } func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { ... self.heightsCache[indexPath] = newCellHeight ... } // MARK: - UITableViewDelegate func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { let height = self.heightsCache[indexPath] if height != nil { return height! }else{ return self.cellDefaultHeight } }

[iOS] 取得目前正顯示的view

目的是為了寫一個簡易的show alert message的method //程式碼 extension UIApplication { class func topViewController(base base: UIViewController? = UIApplication.sharedApplication().keyWindow?.rootViewController) -> UIViewController? { if let nav = base as? UINavigationController { return topViewController(base: nav.visibleViewController) } if let tab = base as? UITabBarController { if let selected = tab.selectedViewController { return topViewController(base: selected) } } if let presented = base?.presentedViewController { return topViewController(base: presented) } return base } } //用法 let presentedView = UIApplication.topViewController() AlertMessageUtils.showSimpleAlert("系統通知", message: "電量\(values[0])%", view: presentedView!) 參考︰Find the current top view controller for your iOS application https://gist.github.com/snikch/3661188

[IOS] xcode 複製專案並修改專案名稱

xcode 複製專案並修改專案名稱 1.將專案copy到新的folder下(OLD->NEW) 2.用xcode打開OLD.xcodeproj 3.將專案名稱點兩下直接改名,改完後clean and close 4.回到NEW目錄下將所有的資料夾及檔案名稱全改成NEW 5.對NEW.xcodeproj顯示套件內容,用xcode打開project.pbxproj,將所有的OLD換成NEW 6.到manager schemes修改scheme名稱 搞定 !

[IOS] Remote logging

使用 https://logentries.com 註冊完後就直接來新增一個log set                   這裡我是用IOS                     這裡我是設定App名稱               下載lib到Project裡,把 lelib 資料夾拉進xcode裡           很貼心,把相關程式都寫出來                                         完成!超簡單!      

[IOS] 一些切割圖片的套件

可以在圖片上拉一個隨意的方形來切割 (Objective-C) https://github.com/myang-git/iOS-Image-Crop-View   先設定一個圖形的mask,讓圖片可以在後面拖拉縮放(Objective-C) https://github.com/DuncanMC/CropImg   https://github.com/gavinbunney/Toucan

[Swift] 將 TableView 或 CollectionView 的 Cell 加上類似 button 的 TouchDown 的效果

class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate { override func viewDidLoad() { super.viewDidLoad() self.tableView.dataSource = self self.tableView.delegate = self // 加上這一行才不會看不到TouchDown的效果 self.tableView.delaysContentTouches = false //... } //... // MARK: - UITableViewDelegate func tableView(tableView: UITableView, didHighlightRowAtIndexPath indexPath: NSIndexPath) { let cell = tableView.cellForRowAtIndexPath(indexPath)! cell.alpha = 0.3 } func tableView(tableView: UITableView, didUnhighlightRowAtIndexPath indexPath: NSIndexPath) { let cell = tableView.cellForRowAtIndexPath(indexPath)! cell.alpha = 1 } }

[Swift] 幫 UITextField 增加一個 done 按鈕

func addDoneButtonOnKeyboard(targetField:UITextField) { let doneToolbar: UIToolbar = UIToolbar(frame: CGRectMake(0, 0, 320, 50)) doneToolbar.barStyle = UIBarStyle.BlackTranslucent let flexSpace = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.FlexibleSpace, target: nil, action: nil) let done: UIBarButtonItem = UIBarButtonItem(title: "Done", style: UIBarButtonItemStyle.Done, target: self, action: Selector("doneButtonAction")) var items = Array<UIBarButtonItem>() items.append(flexSpace) items.append(done) doneToolbar.items = items doneToolbar.sizeToFit() targetField.inputAccessoryView = doneToolbar }

[iOS] Log file for iOS

目的︰用檔案記錄log,以時間組成檔名(yyyyMMddHHmmss),只保留7天 做法︰ 1. 使用XCGLogger來記錄log 2. 每次APP啟動時,檢查log檔案是否有超過7天的,超過就刪除 // AppDelegate.swift import XCGLogger struct MyVariables { static let logger = XCGLogger.defaultInstance() static let documentsPath = NSHomeDirectory() + "/Documents" } class AppDelegate: UIResponder, UIApplicationDelegate { func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { // 清除7天前的log檔 cleanOldLogFile() // 產生此次log的檔名 let postFixFormatter = NSDateFormatter() postFixFormatter.dateFormat = "yyyyMMddHHmmss" postFixFormatter.locale = NSLocale.currentLocale() let logFileName = "Ticket_" + postFixFormatter.stringFromDate(NSDate()) + ".log" let logFileWithFullPath = MyVariables.documentsPath.stringByAppendingString("/\(logFileName)") let dateFormatter = NSDateFormatter...

[iOS] iPhone 尺寸圖

[Swift] UIView Shadow

為UIView加上陰影 backView.layer.shadowOffset = CGSize(width: 3, height: 3) backView.layer.shadowOpacity = 0.7 backView.layer.shadowRadius = 2 backView.layer.shadowColor = UIColor(hexString: "#3A4355")!.CGColor 參考︰ Shadow effect in swift on UIView http://gracefullycoded.com/shadow-effect-in-swift-on-uiview-uilabels/ Playing with UIView shadows in Swift http://mookid.dk/oncode/archives/3780