changing contact add buttons color in swift - ios

Does anybody know how to give a custom text color to the circled + sign in ContactAdd button type? Before I was thinking the circled + is the actual title of the button but I was wrong.
var addButton=UIButton.buttonWithType(UIButtonType.ContactAdd) as UIButton
println("this is the current title \(addButton.currentTitle)") \\gives nil

You can use the tint color property. Something like this:
addButton.tintColor = UIColor.blueColor()

Related

UIButton highlight color overlaps text when the button is pressed

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

Find text color of button in swift4

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)

Customize Text Field

Hi I want to build some thing that look like the picture !
my problem is that text field can't be two section and use tiny pictures in it just like a picture
I want to make some thing just like the picture even the green part in the right of the each text field
here is what I want to do
Make a custom view and add it as
textField.rightViewMode = .always
// Set rightview mode
var rightImageView = UIImageView(image: UIImage(named: "image_icon"))
textField.rightView = rightImageView// Set right view as image view }
//textField Its your textfield object , Change it with your own
Try like this

How to Edit UIButton Attributes Outside of UIButton [duplicate]

This question already has answers here:
Change button background color using swift language
(12 answers)
Closed 6 years ago.
I am trying to make a settings page where if you select the 'Red' theme, then the red button's background goes red and the 'Blue' theme button's background goes white and vice versa. My problem is that I do not know how to edit another UIButton outside of the actual UIButton code. I know to edit the background color of regular UIButton you would write:
sender.backgroundColor = .red
However I am not sure how to do this outside the UIButton's code.
I have tried this:
themeCRed(sender.backgroundColor = .white)
(ThemeCRed is the button's name)
But I get the error, "Cannot convert value of type '()' to expected argument type 'UIButton'"
How can I edit the attributes of the other UIButton outside of it's function block?
If you know the intended outcome and there's few variations then forget about the sender and just set the intended uicolor to the desired uicolor
I don't sure that i understand you correct, but may be just make
#IBOutlet var myButton: UIButton!
in your ViewController or something...
and
myButton.backgroundColor = .white
hm?
You just need to identify the event of theme change and need to change the background colour of the buttons like below
yourButton.backgroundColor = UIColor.red

Changing tintColor to default (blue) in NavBar

I can change the tintColor for my App (everywhere) in a setting pane.
When I change the tintColor, and after that try to return to the default tint color, some buttons in NavBar don't return to blue, how can I handle this?
To verify:
- create a new project Master/Detail
- In the detail view: add Two buttons, named: "Red Interface" and "Blue interface"
- In DetailViewController, add the actions
#IBAction func tapRed(sender: AnyObject) {
view.window!.tintColor = UIColor.redColor()
}
#IBAction func tapBlue(sender: AnyObject) {
view.window!.tintColor = nil
}
Now run the application, create a timestamp, go to detail, tap redInterface, then blue interface
That's OK in the Detail View, but when you return to Master, the "+" button item is red, not blue.
I can fix the problem by setting a real blue color instead of nil, but that's not a long term solution, if Apple change the default tintColor.
Is this a bug? Is there something I can do to bypass this problem?
A quick workaround would be to fetch the default tint color once on the initial app load and store it somewhere (i.e. in the user defaults)
From Apple's iOS 7 UI Transition Guide (Specifically under the Using Tint Color section).
By default, a view’s tint color is nil, which means that the view uses its parent’s tint. It also means that when you ask a view for its tint color, it always returns a color value, even if you haven’t set one.
That's a good workaround!
In fact, I don't even need to store the color.
If I change to
#IBAction func tapBlue(sender: AnyObject) {
view.window!.tintColor = UIButton(type:UIButtonType.System).titleColorForState(.Normal)
}
That gives me the correct blue color, even if I changed the tintColor (probably because I don't address a button in the view hierarchy)

Resources