9 Notes for me in June Swift 4.2
1. Border in Label
This example to set a border around UILabel type.
2. How to set Corner Radius use KeyPath
you can set in bar Identity inspector in file XIB or NIB
look in Identity inspector
set in Attributes inspector off to on
must set in extension
- layer corner radius
3. Convert URL To HTML
4. Filter by Device type
5. Error in debug area 'Could not load NIB in bundle'
Error response in debug area:
2019-06-10 12:04:23.998459+0700 YourApps STG[1835:589577] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </var/containers/Bundle/Application/D3130733-A694-48DE-FC40-FA7BD9C74A36/YourApps STG.app> (loaded)' with name 'TermsCondition''
Solution :
How to solve this bug -> recreate new UIView " UIView.xib and UIView. swift" file and don't copy source code
6. Realm append data to a type List<t>
source from: https://stackoverflow.com/questions/33726606/realm-append-data-to-a-type-listt
and this my complete solution
7. SegmentedControl Set CornerRadius
8. SegmentedControl Custom Fonts size
In Swift 4.2, NSFontAttributeName has been replaced with NSAttributedString.Key.font
9. Capital in UILabel in first word
Swift apply .uppercaseString to only the first letter of a string
let inString = "data in"
inString. capitalizingFirstLetter // Data in
https://stackoverflow.com/a/26306372/8366535
This example to set a border around UILabel type.
label.layer.borderColor = UIColor.green.cgColor
label.layer.borderWidht = 2.0
you can set in bar Identity inspector in file XIB or NIB
look in Identity inspector
set in Attributes inspector off to on
must set in extension
extension UILabel {
@IBInspectable
var selfCornerRadius: Bool {
get {
return false
} set {
if newValue {
self.layer.cornerRadius = self.frame.size.height / 2
} else {
self.layer.cornerRadius = 0.0
}
}
}
}
- layer corner radius
3. Convert URL To HTML
func webToHtml() { let testUrl = URL(string: "http://youURls.html") var html = NSString() do { html = try NSString(contentsOf: testUrl!, encoding: String.Encoding.isoLatin1.rawValue) print(html) self.label.attributedText = "\(html)".convertHtml() // check converhtml in 9 note may } catch { print(error) } }
4. Filter by Device type
if UIDevice().userInterfaceIdiom == .phone {
switch UIScreen.main.nativeBounds.height {
case 1136:
print("iPhone 5 or 5S or 5C")
case 1334:
print("iPhone 6/6S/7/8")
case 1920, 2208:
print("iPhone 6+/6S+/7+/8+")
case 2436:
print("iPhone X, XS")
case 2688:
print("iPhone XS Max")
case 1792:
print("iPhone XR")
default:
print("Unknown")
}
}
5. Error in debug area 'Could not load NIB in bundle'
Error response in debug area:
2019-06-10 12:04:23.998459+0700 YourApps STG[1835:589577] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </var/containers/Bundle/Application/D3130733-A694-48DE-FC40-FA7BD9C74A36/YourApps STG.app> (loaded)' with name 'TermsCondition''
Solution :
How to solve this bug -> recreate new UIView " UIView.xib and UIView. swift" file and don't copy source code
6. Realm append data to a type List<t>
source from: https://stackoverflow.com/questions/33726606/realm-append-data-to-a-type-listt
and this my complete solution
var listArray: List<DataArray>?
var appendData: [DataArray] = []
public override func viewDidLoad() {
super.viewDidLoad()
listArray = REALM.all(DataArray.self).first?.options
for list in listArray! {
appendData.append(manual)
}
}
self.segmentedControl.layer.cornerRadius = 15
self.segmentedControl.layer.borderColor = UIColor.white.cgColor
self.segmentedControl.layer.borderWidth = 1
self.segmentedControl.layer.masksToBounds = true
Or8. SegmentedControl Custom Fonts size
In Swift 4.2, NSFontAttributeName has been replaced with NSAttributedString.Key.font
segmentedControl.setTitleTextAttributes([NSAttributedString.Key.font:
UIFont.systemFont(ofSize: 16)], for: .normal)
https://stackoverflow.com/a/50710084/83665359. Capital in UILabel in first word
Swift apply .uppercaseString to only the first letter of a string
extension String {
func capitalizingFirstLetter() -> String {
return prefix(1).uppercased() + self.lowercased().dropFirst()
}
mutating func capitalizeFirstLetter() {
self = self.capitalizingFirstLetter()
}
}
How to use:let inString = "data in"
inString. capitalizingFirstLetter // Data in
https://stackoverflow.com/a/26306372/8366535
No comments: