ios – 在MonoTouch中更改UIPageControl点的颜色

我想知道MonoTouch是否允许开发人员改变UIPageControl点的颜色以适应浅色背景 – 它们似乎是固定的白色,这使得它们很难在浅色纹理背景上看到.

我知道没有可用的公共API,但我想知道是否在MonoTouch中内部实现了任何改进.

否则,在浅色背景上使用UIPageControl的推荐方法是什么?

最佳答案 我翻译了这个.我不确定它会起作用,但它确实可以编译.请注意,链接到的页面包含注释,表明Apple对此代码不满意并可能拒绝它:

using System;
using MonoTouch.Foundation;
using MonoTouch.UIKit;

namespace Whatever
{
    public class StyledPageControl : UIPageControl
    {
        public StyledPageControl () : base()
        {
        }

        public override int CurrentPage {
            get {
                return base.CurrentPage;
            }
            set {
                base.CurrentPage = value;
                string imgActive = NSBundle.MainBundle.PathForResource("activeImage", "png");
                string imgInactive = NSBundle.MainBundle.PathForResource("inactiveImage", "png");
                for (int subviewIndex = 0; subviewIndex < this.Subviews.Length; subviewIndex++)
                {
                    UIImageView subview = this.Subviews[subviewIndex] as UIImageView;
                    if (subviewIndex == value) 
                        subview.Image = UIImage.FromFile(imgActive);
                    else
                        subview.Image = UIImage.FromFile(imgInactive);
                }
            }
        }

        public override int Pages {
            get {
                return base.Pages;
            }
            set {
                base.Pages = value;
                string img = NSBundle.MainBundle.PathForResource("inactiveImage", "png");
                for (int subviewIndex = 0; subviewIndex < this.Subviews.Length; subviewIndex++)
                {
                    UIImageView subview = this.Subviews[subviewIndex] as UIImageView;
                        subview.Image = UIImage.FromFile(img);
                }
            }
        }
    }
}
点赞