developer's diary

最近はc#のエントリが多いです

UIViewを10000個重ねてグラデーションにしてみたら、起動に40秒かかってしまっった。

Xamarin Studio で弄り中。

width:100,height:10の四角形をループで10000個重ねて見たら、iOSシュミレータで起動に40秒くらい。なるほど。実機だと落ちます(ぁ

実機は2900くらい重ねると落ちました。

f:id:mitsugi-bb:20130301004015p:plain

using System;
using MonoTouch.UIKit;
using System.Drawing;
namespace UIKitExample
{
    public class UIViewExample : UIViewController
    {

        public UIViewExample ()
        {
            RectangleF bounds = this.View.Frame;
            UIView uiview1 = new UIView (bounds);
            uiview1.BackgroundColor = new UIColor (0.8f, 0.0f, 0.1f, 0.8f);

            for (int i = 0; i < 10000; i++) {
                float x = 0.0f;
                float y = 0.0f;
                float width = 100.0f;
                float height = 10.0f;

                x = x + (float)i*0.01f;
                y = y + (float)i*0.01f;

                float red = 0.0f + ( ( float ) i * 0.0001f);
                float green = 0.0f;
                float blue = 0.0f;
                float alpha = 1.0f;
                UIColor color = new UIColor(red, green, blue, alpha);

                UIView uiview2 = new UIView ( new RectangleF(x,y,width,height));
                uiview2.BackgroundColor = color;
                uiview1.AddSubview(uiview2);
            }

            this.View.AddSubview(uiview1);
        }
    }
}