Skip to content

Commit

Permalink
add debugFont + manipulation method
Browse files Browse the repository at this point in the history
  • Loading branch information
nsnull0 committed Jul 8, 2017
1 parent b2129df commit 808a7a0
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 4 deletions.
13 changes: 12 additions & 1 deletion Example/ExampleYWProfile/ExampleYWProfile/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ class ViewController: UIViewController {
// Do any additional setup after loading the view, typically from a nib.


let namePlaceHolder:YWNamePlaceHolder = YWNamePlaceHolder(originLocation: CGPoint(x: 0, y:0), _withSize: 60, _yourPlaceholder: "", _fontPlaceHolder: UIFont.boldSystemFont(ofSize: 10))

namePlaceHolder.debugListFontDevice()



Expand All @@ -45,7 +47,16 @@ extension ViewController: UITableViewDelegate, UITableViewDataSource{
let cell = tableView.dequeueReusableCell(withIdentifier: "namePlaceHolderList")

cell!.textLabel!.text = nameList[indexPath.row]
cell!.accessoryView = YWNamePlaceHolder(originLocation: CGPoint(x: 0, y: 0), _withSize: 50, _yourPlaceholder: nameList[indexPath.row], _fontPlaceHolder: UIFont.boldSystemFont(ofSize: 14.0))

let namePlaceHolder:YWNamePlaceHolder = YWNamePlaceHolder(originLocation: CGPoint(x: 0, y: 0), _withSize: 50, _yourPlaceholder: nameList[indexPath.row], _fontPlaceHolder: UIFont.boldSystemFont(ofSize: 14.0))
cell!.accessoryView = namePlaceHolder

if indexPath.row == 6 {
namePlaceHolder.setColor(_textColor: .black, _contentColor: .yellow)
}else if (indexPath.row == 5){
namePlaceHolder.setFont(_textFont: UIFont.init(name: "DamascusBold", size: 10)!)
namePlaceHolder.setFontSize(_staticFontSize: 8.0)
}

return cell!

Expand Down
16 changes: 16 additions & 0 deletions YWNamePlaceholder/ClassModifier/UILabelEx.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ extension UILabel {
let stringSplit = newValue.components(separatedBy: " ")

var strResult = ""

guard stringSplit.count > 1 else {
return
}


for str in stringSplit{
let strProcess = "\(str.characters.first!)"

Expand All @@ -42,4 +48,14 @@ extension UILabel {
return self.font
}
}

var staticFont:CGFloat{
set{
self.font = self.font.withSize(newValue)
}

get{
return self.font.pointSize
}
}
}
31 changes: 28 additions & 3 deletions YWNamePlaceholder/ClassResources/YWNamePlaceHolder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public class YWNamePlaceHolder: UIView {
super.init(frame: frame)
}


lazy private var contentContainer:UIView = UIView()
lazy private var textTitle:UILabel = UILabel()

public init(originLocation: CGPoint,_withSize size: CGFloat,_yourPlaceholder str:String,_fontPlaceHolder font:UIFont) {

Expand All @@ -28,8 +29,8 @@ public class YWNamePlaceHolder: UIView {

func setupProperty(str:String, font:UIFont) {

let contentContainer: UIView = UIView(frame: CGRect(x: 4, y: 4, width: self.bounds.size.width - 8, height: self.bounds.size.height - 8))
let textTitle: UILabel = UILabel(frame: CGRect(x: (self.bounds.size.width / 2.5)/2, y: (self.bounds.size.width / 2.5)/2, width: self.bounds.size.width - (self.bounds.size.width / 2.5), height: self.bounds.size.height - (self.bounds.size.width / 2.5)))
contentContainer = UIView(frame: CGRect(x: 4, y: 4, width: self.bounds.size.width - 8, height: self.bounds.size.height - 8))
textTitle = UILabel(frame: CGRect(x: (self.bounds.size.width / 2.5)/2, y: (self.bounds.size.width / 2.5)/2, width: self.bounds.size.width - (self.bounds.size.width / 2.5), height: self.bounds.size.height - (self.bounds.size.width / 2.5)))


contentContainer.asCircularContent = true
Expand All @@ -43,6 +44,30 @@ public class YWNamePlaceHolder: UIView {

}


public func setFont(_textFont font:UIFont){
textTitle.setAutoFont = font
}

public func setColor(_textColor color:UIColor, _contentColor color2:UIColor){
contentContainer.backgroundColor = color2
textTitle.textColor = color
}

public func setFontSize(_staticFontSize size:CGFloat){
textTitle.staticFont = size
}

public func debugListFontDevice(){
let fontFamilyNames = UIFont.familyNames
for familyName in fontFamilyNames {
print("------------------------------")
print("Font Family Name = [\(familyName)]")
let names = UIFont.fontNames(forFamilyName: familyName)
print("Font Names = [\(names)]")
}
}

public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
Expand Down

0 comments on commit 808a7a0

Please sign in to comment.