Monotouch.Dialog : Section font

戏子无情 提交于 2020-01-15 05:10:06

问题


It it possible to access the font and color properties of the section header and footer or do I need to subclass Section? I changed my UI to all black and everything looks great except my section headers and footers.

Reflection API:

class Login
{
    public string Version = "1.2.3";

    [Section ("Enter your credentials", "Email and password are required")]

    [Entry ("Enter your email address")]
    public string email;

    [Caption ("Password"), Password ("Enter your password")]
    public string password;

    [OnTap ("Login")]
    [Alignment (UITextAlignment.Center)]
    public string Logon;
}

Element API:

return new RootElement ("Login") {
    new Section() {
        new StringElement ("Version", "1.2.3")
    },
    new Section ("Enter your credentials", "Email and password are required") {
        new EntryElement("Email", "Enter your email address", "azcoov"),
        new EntryElement("Password", "Enter your password", "password", true),
        new StringElement("Logon", Login)
    }
}

回答1:


Section headers and footers can either be specified as strings or UIViews, there is sadly, nothing in between.

If you want to have custom headers/views, you would need to create a UILabel and use that in your constructor to the Section type (only available for the Elements API).

Something like:

var header = new UILabel (new RectangleF (0, 0, 320, 48)){
    Font = UIFont.BoldSystemFontOfSize (22),
    BackgroundColor = UIColor.Red
}

new Section(header, footer) {
    ...
 }



回答2:


Using Miguel's answer I was able to get what I needed:

RootElement CreateRoot (String lat, String lng)
{
    var header = new UILabel (new RectangleF (0, 0, 320, 48)) {
        Font = UIFont.BoldSystemFontOfSize (22),
        BackgroundColor = UIColor.Black,
        TextColor = UIColor.White,
        Text = "This is my header"
    };
    var footer = new UILabel (new RectangleF (0, 0, 320, 48)) {
        Font = UIFont.BoldSystemFontOfSize (22),
        BackgroundColor = UIColor.Black,
        TextColor = UIColor.White,
        Text = "This is my footer"
    };

    var rootElement = new RootElement ("Location Example"){
        new Section (header, footer){
            new StyledStringElement("Latitude", lat),
            new StyledStringElement ("Longitude", lng)
        },
        new Section() {
            new StringElement ("Get location", GetLocation),
            new StringElement ("Clear location", ClearLocation),
            new StringElement ("Show on Map", ShowOnMap)
        }
    };
    return rootElement;
}


来源:https://stackoverflow.com/questions/5590161/monotouch-dialog-section-font

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!