11

Xamarin Forms – Set entry clear icon color on iOS

 3 years ago
source link: https://depblog.weblogs.us/2021/03/28/xamarin-forms-set-entry-clear-icon-color-on-ios/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Xamarin Forms – Set entry clear icon color on iOS

Here is a small piece of code that you can use as a Xamarin Forms effect to hook into your entry.
It allows changing the color of the clear icon that is available inside the native entry control of iOS ( when enabled ).

if (Control is UITextField textField)
    //Enable the clear icon
    textField.ClearButtonMode = UITextFieldViewMode.WhileEditing;
    //Get hold of the clear icon inside the text field
    UIButton clearButton = textField.ValueForKey(new Foundation.NSString("clearButton")) as UIButton;
    //Set the desired color
    clearButton.TintColor = UIColor.Red;
    UIImage clearImage = UIImage.GetSystemImage("xmark.circle.fill");
    //Override the regular image with the colored one
    clearButton.SetImage(clearImage.ImageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate), UIControlState.Normal);

With this platform specific code, we can get a hold of the UIButton inside the UITextField and set a color. Than again pasting it into the UIButton.

As always a full example can be found here https://github.com/Depechie/EntryClearIconColor

Posted on March 28, 2021March 28, 2021Author DepechieCategories ProgrammingTags Effects, Entry, Xamarin

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Comment

Name *

Email *

Website

Notify me of follow-up comments by email.

Notify me of new posts by email.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Post navigation


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK