UITextField Appearance

ShaneMunnShaneMunn AUBeta ✭✭
edited October 2012 in Xamarin.iOS

I'm under the impression that you can set the font for all UITextFields using the appearance protocol. When I access UITextField.Appearance, all I get access to is BackgroundColor. Am I mistaken, or is there a binding issue with the appearance protocol in MT?

Cheers,
Greg

Posts

  • NicWiseNicWise NZMember, Insider, Beta mod

    If you look here:

    http://stackoverflow.com/questions/9424112/what-properties-can-i-set-via-an-uiappearance-proxy

    then run this:

    cd /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.0.sdk/System/Library/Frameworks/UIKit.framework/Headers/

    then

    grep -H UI_APPEARANCE_SELECTOR ./* | sed 's/ __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_5_0) UI_APPEARANCE_SELECTOR;//'

    It shows your everything. UITextField has nothing....

  • ShaneMunnShaneMunn AUBeta ✭✭

    Oh. Thanks @nicwise. I was sure I'd see some code setting font information.

    Cheers,
    Greg

  • JonathanPeppersJonathanPeppers USInsider, Beta, University ✭✭

    Yeah, this is why I generally subclass UITextField to "fake" UIAppearance for it.

    Doesn't work in all cases though, you'll bump into UISearchBar and other things that use UITextField internally.

  • KojiIshiiKojiIshii JPMember

    @nicwise UILabelAppearance has the Font property though UILabel.h has no UI_APPEARANCE_SELECTOR, so it looks like the rule is not always right.

    I also tried:

    var appearance = UITextField.AppearanceWhenContainedIn(typeof(UISearchBar));
    Messaging.void_objc_msgSendSuper_IntPtr (appearance.SuperHandle, Selector.GetHandle ("setFont:"), font.Handle);
    

    and it looks like it works good.

Sign In or Register to comment.