1

どうすれば/これを行うことができるかどうか疑問に思っています.UIViewのグループをスーパービューの中央に配置します。最終結果は、スーパービューの中心にあるビューの「グループ」になります。

4

1 に答える 1

1

それは 2 ステップのプロセスです。最初に UIView を配列に追加し、高速列挙を行ってそれらを「グループ」として中央に配置します。

//step 1: create the objects
self.label1= [[UILabel alloc]init];
self.label1.font=[UIFont systemFontOfSize:30.0];
self.label1.text=@"1";

self.label2= [[UILabel alloc]init];
self.label2.font=[UIFont systemFontOfSize:30.0];
self.label2.text=@"2";

self.label3= [[UILabel alloc]init];
self.label3.font=[UIFont systemFontOfSize:30.0];
self.label3.text=@"3";


//step2: create the array and add the objects to the array
self.arrayOfViews=[[NSMutableArray alloc]initWithCapacity:4];
[self.arrayOfViews addObject:self.label1];
[self.arrayOfViews addObject:self.label2];
[self.arrayOfViews addObject:self.label3];



//step3: use fast enumeration to be able to control them as "group"
for(UIView* currentViewObject in self.arrayOfViews)
{
    currentViewObject.alpha=0.3;
    currentViewObject.frame=CGRectMake(self.view.bounds.size.width/2-sizeOfObject/2,self.view.bounds.size.height/2-sizeOfObject/2,sizeOfObject,sizeOfObject);
    [self.view addSubview:currentViewObject];
}

ステップ 1 とアルファ設定は、ここでのテスト目的のためだけのものです。

お役に立てれば。

于 2013-03-02T02:20:35.517 に答える