"Swift" iOS Development Tips (i)

Source: Internet
Author: User

Objective

Learning while developing, accumulating experience, summarizing the records here

Statement
Welcome reprint, but please keep the original source of the article:)
Blog Park: http://www.cnblogs.com
Farmer Uncle: Http://over140.cnblogs.com

1. Hide/Show Password function

Light settings securetextentry not yet, you will find Uitextfield when switching to display password will be a blank character, looking at the awkward, you need to change the securetextentry after the following settings:

let pwd = Psdfield.text
Self.psdField.text = pwd +" "
Self.psdField.text = pwd

2. Get the name of the current class

String.fromcstring (Object_getclassname (self))

Note: It can also be obtained through _stdlib_getdemangledtypename, but if you go inside the parent class, you can only take the name of the parent class.

3. Internationalization

Find. \ (-name'*.M'-o-name'*.h'\)-print0 | Xargs -0Genstrings-o en.lproj 

any string that uses nslocalizedstring can be found, supports subdirectory lookups, and takes care of replacing En.lproj

4, UITableView split line display problem

Remove Split Line: Set UITableView's Separatorstyle = Uitableviewcellseparatorstyle.none

Remove unnecessary split lines: set UITableView Tablefooterview = UIView () (if not set, it will be ugly, no matter if there is no data will show the split line)

To handle the problem of setting the left margin of the iOS8 divider to 0 failure, refer to here (http://stackoverflow.com/questions/25770119/ Ios-8-uitableview-separator-inset-0-not-working):

Func TableView (Tableview:uitableview, Willdisplaycell Cell:uitableviewcell, Forrowatindexpath Indexpath:nsindexpath ) {


//Remove seperator Inset
ifCell.respondstoselector ("Setseparatorinset:") {
Cell.separatorinset = Uiedgeinsetszero
}

//Prevent the cell from inheriting the Table View ' s margin settings
ifCell.respondstoselector ("Setpreservessuperviewlayoutmargins:") {
Cell.preservessuperviewlayoutmargins =false
}

//explictly Set your cell ' s layout margins
ifCell.respondstoselector ("Setlayoutmargins:") {
Cell.layoutmargins = Uiedgeinsetszero
}

}

5. Formatted Digital output k/m

Extension String {

PublicFunc substring (startindex:int, endindex:int), string{
return(Self asNSString). Substringwithrange (Nsrange (Location:startindex, Length:endindex-startindex))
}

}

PublicStaticFunc Prettynumber (num:double), string{
if(Num <10000) {
return"\ (Int (num))";
}Elseif(Num <100000) {
return"\ (num/1000.0)". SUBSTRING (0, EndIndex:4) +"K"
}Elseif(Num <1000000) {
return"\ (num/1000.0)". SUBSTRING (0, EndIndex:3) +"K"
}Elseif(Num <100000000) {
return "\ (num/1000000.0)". SUBSTRING (0, EndIndex:4) +"M"
}Elseif(Num <1000000000) {
return"\ (num/1000000.0)". SUBSTRING (0, EndIndex:3) +"M"
}Elseif(Num <100000000000) {
return"\ (num/1000000000.0)". SUBSTRING (0, EndIndex:4) +"M"
}Elseif(Num <1000000000000) {
return"\ (num/1000000000.0)". SUBSTRING (0, EndIndex:3) +"M"
}
return"INF";
}

6, determine whether the screen is a horizontal screen

     Public Static func isislandscape (), Bool {        return uideviceorientationislandscape ( Uidevice.currentdevice (). Orientation) | | Uiapplication.sharedapplication (). statusbarorientation = = Uiinterfaceorientation.landscapeleft  | | Uiapplication.sharedapplication (). statusbarorientation = = uiinterfaceorientation.landscaperight    } 

7. URL Encoding

Text.stringbyaddingpercentencodingwithallowedcharacters (. Urlhostallowedcharacterset ())

This text type is a String, commonly used in search function, in the URL contains the searched keyword, if not processing search Chinese or with spaces in English will crash directly

"Swift" iOS Development Tips (i)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.