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

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...

Related

NSMutableAttributedString not appending? [duplicate]

This question already has answers here:
Can not change UILabel text color
(6 answers)
Closed 4 years ago.
I am trying to append two NSAttributedString's with the following values and I get the first NSAttributedString but not the second. The label is inside a UITableView. I have no idea what is causing this problem.
NSMutableAttributedString ms = new NSMutableAttributedString();
NSAttributedString attributedString = new NSAttributedString("Add New Seller ", new UIStringAttributes(){
Font = UIFont.FromName("Quicksand-Regular", 17)});
NSAttributedString attributedString1 = new NSAttributedString("+", new UIStringAttributes(){
Font = UIFont.FromName("Quicksand-Regular", 17),
ForegroundColor = new UIColor(33f, 201f, 130f, 1f)});
ms.Append(attributedString);
ms.Append(attributedString1);
cell.seller.AttributedText = ms;
Your second NSAttributedString is there appended in the final NSMutableAttributedString but you might not see it because it's white. Your issue as #Larme indicated in the comments is with the way you are creating your UIColor.
UIColor accepts nfloat values between 0 and 1. When you say new UIColor(33f, 201f, 130f, 1f) the resulting Color will be White because it will treat any value over 1.0 as 1.0, hence
new UIColor(33f, 201f, 130f, 1f) has the same result as new UIColor(1f, 1f, 1f, 1f).
To fix your code you just need to change the UIColor initialization as
new UIColor(33f/255, 201f/255, 130f/255, 1f)
As you see dividing your 3 values of the color (RGB) by 255. The last value represents the alpha.
Hope this helps.-

How to highlight match string text in label [duplicate]

This question already has answers here:
ios swift: Is it possible to change the font style of a certain word in a string?
(3 answers)
How to change colour of the certain words in label - Swift 3 [duplicate]
(1 answer)
Closed 5 years ago.
I want to highlight match text in UILabel as
Here's my code, but I do not know how to highlight each matched text with background color of yellow
//Highlight Text
let string = self.myInterestsLbl.text
if string?.range(of:"Fashion") != nil {
print("Highlight Fashion")
}

UITextField textColor updates in iOS10, not in iOS 11

My code fragment is very small:
self.textField.textColor = color
This is called in response to user interaction. It has been working for years. On my iOS 10 device it still works. On my iOS 11 device, the color does not change until I tap in the text field.
Bug? Feature? Workaround? Suggestions welcome.
You might need to update/reset your UITextField text right after the color change:
self.textField.textColor = color
self.textField.text = "Hi! I've changed of color!!"
Andrew update, more practical stuff:
self.textField.textColor = color
self.textField.text = self.textField.text
I can trigger the text color change to take effect by adding this line below the single line cited above:
self.textField.text = self.textField.text
However, given the facts above, it still looks to me like a bug outside of my code. Or, at least, a change of the implicit class contract.

Changing custom made attribute inspector value with swift [closed]

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.

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