Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
How to remove this white border around the angles in the shown button?
Create your button this way:
let button = UIButton(type: UIButtonType.system)
button.titleLabel?.font = UIFont.preferredFont(forTextStyle: UIFontTextStyle.body)
button.setTitleColor(UIColor.black, for: UIControlState.normal)
button.backgroundColor = UIColor.white
button.layer.cornerRadius = 4
Related
I'm a beginner with swift and have reviewed this site to understand how importing custom fonts work. I've also reviewed this StackOverflow question which didn't seem to solve my specific issue
Upon reviewing the site, I've added the .tts file Lovelo-Black to the project and plist.
private let loginButton: UIButton = {
let button = UIButton()
button.setTitle("log in", for: .normal)
button.layer.masksToBounds = true
button.layer.cornerRadius = Constants.cornerRadius
button.backgroundColor = UIColorFromHex(rgbValue: 0x00FF9C,alpha: 1)
button.setTitleColor(.black, for: .normal)
button.titleLabel?.font = UIFont(name: "Lovelo-Black") //issue here
return button
Is it possible to make the button use the Lovelo-Black font? Ideally, I would like it to look like this
If it is possible, what should I replace the 8th line with?
Make sure you add the fonts correctly to your project..
check this link
Use the correct font name
button.titleLabel?.font = UIFont(name: "Lovelo Black", size: size)
In swiftUI you can use custom function from Font to initialise and use any custom fonts. have a look at bellow example code.
Font.custom("Lovelo_Black", size: 24)
Which generates bellow result
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I have 2 UIButton as shown in below image. Here I need to customize exactly the same for both, mean texts, how could I do this.
Suggest how could I do this either in storyboard (using label/view ..) or programmatically. Guide me with some piece of code for NSAttributtedstring in case of label or button text as shown in image.
You can use this below func :
extension UILabel {
func setAttributes(price : String) {
let font:UIFont? = UIFont.boldSystemFont(ofSize: 22)
let fontSuper:UIFont? = UIFont.boldSystemFont(ofSize: 15)
let aDotRange = (price as NSString).range(of: ".")
let attString:NSMutableAttributedString = NSMutableAttributedString(string: price, attributes: [.font:font!])
attString.setAttributes([.font:fontSuper!,.baselineOffset:5], range: NSRange(location:0,length:1))
attString.setAttributes([.font:fontSuper!,.baselineOffset:5],
range: NSRange(location:aDotRange.location,length:4))
attString.setAttributes([.font:font!],
range: NSRange(location:1,length:aDotRange.location - 1 ))
attString.setAttributes([.font:fontSuper!],
range: NSRange(location:aDotRange.location + 4,
length: (price.count) - (aDotRange.location + 4) ))
self.attributedText = attString
}
}
Dummy code :
lblPrice.setAttributes(price: "$249.99 / mon")
lblPrice.layer.cornerRadius = 4
lblPrice.layer.borderWidth = 1.0
lblPrice.layer.borderColor = UIColor.blue.cgColor
lblPrice2.setAttributes(price: "$999.99 / 6 mo")
lblPrice2.layer.cornerRadius = 4
Output :
You can use UIViews and UILabels for designing the buttons and add tapGestures to the UIViews for User interactions.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
QLPreviewController navigationBar Title showing current page number like 2 of 6 but I want to change this title to any String like current file name.
Try this
let lblNavTitle = UILabel(frame: CGRect(x: 60, y: 10, width: view.frame.size.width-110, height: 20))
lblNavTitle?.textAlignment = .center
lblNavTitle?.lineBreakMode = .byTruncatingMiddle
lblNavTitle?.text = "File Name"
navigationItem.titleView = lblNavTitle
OR
Simply set title property like
self.title = "File Name"
May be it will work for you
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I have made a custom attribute inspector for my text field:
#IBInspectable var bottomColor: UIColor = UIColor.clear {
didSet {
if bottomColor == UIColor.clear {
self.borderStyle = .roundedRect
} else {
self.borderStyle = .bezel
}
self.setNeedsDisplay()
}
}
Now I want to set bottomColor to red when the form is submitted with an empty text field. Which would be the best way to do this?
I'm putting my logic here
For do that you need to add bottom border of UITextField
UITextField border for bottom side only in swift OR How to only show bottom border of UITextField in Swift
Then you need to set color of this bottom border that you want
After remove same you need to set 0 width of bottom border of UITextField clear color of border.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I want to display a picker next to a textfield, when the user starts editig. After editing, the picker disappears.
Therefore I changed the width of a textfield like this in textFieldDidBeginEditing:
func textFieldDidBeginEditing(_ textField: UITextField)
{ print ("textFieldDidBeginEditing")
let newSize = CGSize(width: 90.0, height: textfield.frame.height)
let newFrame = CGRect(origin: textfield.frame.origin, size: newSize)
textfield.frame = newFrame
}
In textFieldDidEndEditing the width is reset to the old value.
This works fine the time (beginEditing, endEditing)
In following attempts the with is not changed again (the print statement is reached)
What´s going wrong.
Everything works fine in my test project, try insert textfield.setNeedsDisplay() after set new frame.