为 Monotouch-dialog 元素设置自定义字体 [英] Setting a custom font for Monotouch-dialog elements

查看:36
本文介绍了为 Monotouch-dialog 元素设置自定义字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当 Monotouch Dialog 类被实例化后,有没有办法设置字体?

Is there a way to set the fonts when a Monotouch Dialog class has been instansiated?

[Section("This is the header")]

这将使用带有阴影的默认蓝色文本进行渲染,但我找不到该字体的设置位置.有没有办法覆盖它使用的字体和颜色?

This will render with the default blue text with drop shadow, but I can't find where that font is being set. Is there a way to overwrite which font and color it uses?

推荐答案

我为那些希望替换整个解决方案中的所有节标题的人找到了一个解决方案.在MonoTouch.Dialog 中,有一个名为DialogViewController 的类,它在使用反射API 创建视图时使用.在这里,有一个名为 GetViewForHeader() 的方法.您可以创建一个自定义标签并将其发送回,而不是仅发送回普通的 section.HeaderView.

I found a solution for those looking to replace ALL section headers in the entire solution. In MonoTouch.Dialog, there is a class named DialogViewController which is used when creating views with the reflection API. And in here, there's a method called GetViewForHeader(). Instead of sending back just the normal section.HeaderView, you can create a custom label and send that back.

public override UIView GetViewForHeader (UITableView tableView, int sectionIdx)
{
    var section = Root.Sections [sectionIdx];
    if (!string.IsNullOrEmpty(section.Caption))
    {
        var label = new UILabel();
        label.BackgroundColor = UIColor.FromRGB(89, 41, 17);
        label.TextColor = UIColor.FromRGB(255, 206, 52);
        label.ShadowColor = UIColor.Black;
        label.ShadowOffset = new SizeF(0, 1f);
        label.Font = UIFont.FromName("TitlingGothicFB Cond", 20);

        label.Text = section.Caption;

        return label;
    }
    return section.HeaderView;
}

public override float GetHeightForHeader (UITableView tableView, int sectionIdx)
{
    if (!string.IsNullOrEmpty(section.Caption))
        return 40f;
    return -1;
}

记住设置高度,手动或通过从标签获取高度.你也可以创建一个自定义的 UIView,但一个标签对我来说已经足够了.

Remember to set the height, either manually or by getting the height from the label. You can also create a custom UIView, but a label was sufficient for me.

这篇关于为 Monotouch-dialog 元素设置自定义字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆