Monotouch.Dialog:节字体

时间:2011-04-08 03:40:12

标签: xamarin.ios monotouch.dialog

可以访问节头和页脚的字体和颜色属性,还是需要继承Section?我将我的UI改为全黑,除了我的章节页眉和页脚之外,一切看起来都很棒。

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;
}

元素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)
    }
}

2 个答案:

答案 0 :(得分:12)

章节页眉和页脚可以指定为字符串或UIViews,遗憾的是,它们之间没有任何内容。

如果您想拥有自定义标题/视图,则需要创建UILabel并在构造函数中将其用于Section类型(仅适用于Elements API)。

类似的东西:

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

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

答案 1 :(得分:1)

使用Miguel的答案,我得到了我需要的东西:

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;
}