Changing custom made attribute inspector value with swift [closed] - ios

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.

Related

Swift -How to change the color of the curve on a UISwitch control

How can I change the color of the curve that follows a UISwitch control? I tried changing the borderColor but that's tied to the frame.
This is a sample photo from another question. I want to toggle the color of the silver curve in this photo (not the round button and not the orange background)
I tried these 2 properties but the .layer.borderWidth = 2.0 and .layer.cornerRadius = 15 changes the frame and not the curve
When it's on I want the curve to be .clear and when it's off I want it to be .red
lazy var switchControl: UISwitch = {
let switchControl = UISwitch()
switchControl.addTarget(self, action: #selector(switchValueDidChange(_:)), for: .valueChanged)
}()
#objc func switchValueDidChange(_ sender: UISwitch) {
if (sender.isOn == true) {
sender.layer.borderColor = UIColor.clear.cgColor // this doesn't work
} else {
sender.layer.borderColor = UIColor.red.cgColor // this doesn't work
}
}
Yes as iChirag said this can not be done as of now using the built-in UISwitch.
As to why it's not possible, it's hard to say with certainty. My guess would be that it's because Apple encourages using a limited color palette in their Human Interface Guidelines. The main goal of using colors in an iOS app is basically to communicate information, help the user differentiate separate parts of the UI at a glance or to call attention to user actions. Maybe they think that setting a custom color for the curve of a UISwitch is outside of these purposes.
With that said, it's fairly easy to build your own custom UISwitch if you need this appearance. Here is a tutorial to get you started, hope this helps:
Make custom UISwitch (Part 1)
Change Tint color of UISwitch
mSwitch.tintColor = offColor// Custom color
I believed this doesn't possible without some hacking tips of SDK. But I am proposing to create your own such control using an image.

How do you show multiple lines of text in a UILabel using Swift? [duplicate]

This question already has answers here:
Multiple lines of text in UILabel
(26 answers)
Closed 4 years ago.
Is it possible to show multiple lines of text in a UILabel in Swift?
I currently use a UITextView which has an internal scroll and I would like to avoid a scroll and display statically. I’ve tried placing a number of constraints to achieve this but it doesn’t prevent an internal scroll on the UITextView.
I think you mean UITextView.
Change your text to a UILabel and hook it up as an IBOutlet and then add the following code:
myLabel.numberOfLines = 0
Example:
#IBOutlet weak var myLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
myLabel.text = "This is where all of your text goes..."
myLabel.numberOfLines = 0
}
Set your constraints as normal and this should display the UILabel on multiple lines dependent on how much text you have displayed.
You can simply do the following :
myLabel.numberOfLine = 2
You can also specify 0 to allow your label to use the necessary number of line to display all the content.
You can do that Using StoryBoard also:
Make the lines to 0 or any amount of lines you want

How can change background color with NSMutableAttributedString with animation during time? [duplicate]

This question already has answers here:
Animate a change in part of an NSMutableAttributedString
(3 answers)
Closed 5 years ago.
I want to change background color of text with animation. Does any way exist to set NSAttributedStringKey.backgroundColor with duration time?
I mean in Hello my dear friend , how are you ?
I want to change the background color of friend to yellow color with 2s (second)
Unless you want to change only part of the NSAttributedString
Did you try (Swift 3) the following?
UIView.animate(withDuration: 0.3) {
label.backgroundColor = .red
}
That works for the whole label...

why edges of textfield Get Clipped?

Edges of UITextfield get Clipped form all the corners when i set corner radious property.
does anybody knows why this happening?
thanks!!!
my Code:
override func viewDidLoad() {
super.viewDidLoad()
fullNameTextField.layer.cornerRadius = fullNameTextField.frame.size.height / 2
}
result:
i want to achieve this:
Try setting your border style to none and draw your border using in layer:
fullNameTextField.borderStyle = .none
fullNameTextField.layer.borderColor = UIColor.gray.cgColor
fullNameTextField.layer.borderWidth = 1.0
fullNameTextField.layer.cornerRadius = fullNameTextField.frame.size.height / 2
yes buddy its because your text field contains boder style. in interface builder select your text field and choose rounded boder style if you need border.. attaching an image have a look and you can fix it from storyboard :)

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

Resources