Align UIActivityIndicator next to UILabel in horizontal orientation
I have an UILabel that is centere开发者_如何学JAVAd in the screen. I want to place an UIActivityIndicator 10px left of the label. Everything works fine except for when I rotate the device to horizontal view. How can I make the UIActivityIndicator follow the UILabel when switching orientation?
In InterfaceBuilder?
Select the two objects and use Layout > Embed Objects in > View
Configure the view that forms to stay centered in the layout tab.
Programatically
UIView *container = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 100)] autorelease];
UILabel *label = [[[UILabel alloc] initWithFrame:CGRectMake(100, 0, 400, 100)] autorelease];
[container addSubview:label];
UIActivityIndicatorView *active = [[[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0, 0, 100 , 100)] autorelease];
[container addSubview:active];
[theViewController.view addSubview:container;
container.center = theViewController.view.center;
Though you probably want to keep the handles to the label and activity indicator
精彩评论