I have an edit and a delete tableViewRowAction in my tableViewCell. Currently I'm using the built in emojis to use as my title, but it is too small. How do I make the font larger?
I know we can only customise a limited amount of things in the tableViewRowAction. But is there a way to go around it to make just the title font bigger?
I checked other threads and most of them used:
UIButton.appearance().setAttributedTitle(NSAttributedString(string: "Your Button", attributes: attributes), forState: .Normal)
with a set attribute that determines the font size of course. However, this affects ALL buttons, and that isn't good.
Any help is much appreciated! Thanks!
you are setting this to UIButton so it is set for all UIButton objects.
You can set it for specific button object like,
let myButton: UIButton = UIButton() //your button here
let attributedStr: NSAttributedString = NSAttributedString()
myButton.setAttributedTitle(attributedStr, forState: .Normal)
Update :
You can set title as attributed string.
check Apple documentation for that and refer this answer for more details
Hope this will help :)
Related
This is a normal state of my UIButton:
But when I press on the UIButton, its highlight color should be changed to a different one. And here is what I have:
So, if you can notice, my white text becomes overlapped with the new color. But what I should have as a result is just a different color of the highlight and always the white text. Like so:
What I am doing so far is:
In Attribute Inspector in my xib file I changed the Highlight Color to a new one.
I also use updateButton.setTitleColor(.white, for: .highlighted) in my code but it doesn't help.
I've also taken a look at this question: UIButton background color overlaps text on highlight but the accepted answer didn't help much.
Similar to myButton.setTitleColor(.white, for: .normal) please try setting title colour for .highlighted state. That should work for you.
You can refer:
https://developer.apple.com/documentation/uikit/uibutton/1623993-settitlecolor
This myButton.setTitleColor(.white, for: .normal) doesnt change title color when highlighted , Its for normal state. If you want to change textColor when button is highlighted, you need to use myButton.setTitleColor(.white, for: .highlighted)
Also when you change state config in storyboard
you can set Text Color
If its a custom Button you can override isHighlighted method and do what you need like
class MyButton : UIButton {
override var isHighlighted: Bool{
didSet {
tintColor = isHighlighted ? UIColor.red : UIColor.white
backgroundColor = UIColor.blue
.....
// do what you need
}
}
As your button is subclass of UIView class CellButton: UIView {}, you need to handle touches begin and end events in custom CellButton and handle the appearance of the view. If it was subclass of UIButton then it would have handled automatically for you :)
You can also try with gestures, for more info you can refer: https://developer.apple.com/documentation/uikit/touches_presses_and_gestures/handling_uikit_gestures/handling_tap_gestures
I would like to change the size of an Emoji. However, I have been searching documentation on how to do this with no luck. Is it possible to adjust the size of an Emoji before sending it.
Pseudocode:
if ( textField.text.isSingleEmoji ){
// return textField.text.enlargeSize
}
I was trying to make GuessTheFlag game. Instead of putting the flags with photo assets. I wanted make it with flag emoji. Here is the solution for how to increase size of emoji with Swift.
Increasing emoji's font size for button:
var countryTurkey = "🇹🇷"
button.setTitle(countryTurkey, for: .normal)
button.titleLabel?.font = .systemFont(ofSize: 120.0)
Also please note that style of the button needs to be Default. In order to do that click to the button, select the Attributes inspector and select the Style to "Default"
Increasing emoji's font size for label:
var countryTurkey = "🇹🇷"
label.text = countryTurkey
label.font = .systemFont(ofSize: 120)
I am working on app and I give UIButton text color from storyboard (Different for default and selected), I want both text color in a variable.
Anyone help me with this problem.
I have one solution for this problem " Take 'color code' of this color and give it to variable"
Anyone has any other short method for this problem.
Because if I use 'color code' then in future when I change color of button text then Then also work on that 'color code'.
You need to call titleColor() method of UIButton
let color = btnOutletExample.titleColor(for: .normal) or your desired state
try this
let titleColor: UIColor = yourButton.currentTitleColor
At the end of viewDidLoad, you can add the following to capture the color information:
let defaultTextColor = myButton.titleColor(for: .normal)
let selectedTextColor = myButton.titleColor(for: .selected)
You could pull the colour out of the element you configured in your storyboard, using the following code.
let btnTextColor = self.myBtnOutlet.titleLabel.titleColor(for: .normal)
I am new to Xamarin and iOS. I am setting Image on Button via both the way design and programatically.
Design Way :
my Image name is Pen.png.
Programatically Way :
btnEditAccount.SetImage(UIImage.FromFile("Pen.png"), UIControlState.Normal);
But in Both case My Image not set well. It Complete White Image. But on Button it display below Image.
Output :
I Expect :
Is there any Property I miss for my understing ?
How to set full white Image on Button.
Any Help be Appreciated.
button.setImage(UIImage.init(named: "icon (5).png"), forState: .Normal)
button.tintColor = UIColor.clearColor()
Finally I set TintColor to Button Image and it will solve the Probelm.
Programatically this way
btnEditAccount.SetImage(UIImage.FromFile("Pen.png"), UIControlState.Normal);
btnEditAccount.TintColor = UIColor.White;
When I create a UIButtonin Swift, e.g. by
let aButton = UIButton()
aButton.setTitle("Title", forState: UIControlState.Normal)
it seems like I'm not getting the same button style as I would get if I added a button in Interface Builder. Specifically, the title color is white instead of the default "tint color", leaving the button invisible. Now I want this button to look like any other button, so I don't want to specify my own colors.
Setting the normal (not pressed) state can be done with:
aButton.setTitleColor(self.tintColor, forState: UIControlState.Normal)
So far, so good. But the text color does not change when the button is pressed. I guess, for that I need
aButton.setTitleColor(/* somehting here */, self.tintColor, forState: UIControlState.Highlighted)
Ideally without hardcoding the color, what do I need to substitute above to get the default pressed button color? Or is there even a simpler way to just create a UIButton with default style?
In order to declare a button of the same (default) style as in the storyboard/interface builder, use the following code to instantiate it:
let aButton = UIButton(type: .system)
Otherwise the button is of type custom.
You can read about the various button types here.