嗨,我是 ios 开发的新手。我正在尝试将标签从视图拖到工具栏...但是标签将位于工具栏的背面。我希望将标签拖到工具栏的前面...请就这个问题帮助我..... .这是我到目前为止所做的代码
- (void)viewDidLoad {
[super viewDidLoad];
UIToolbar *backgrdtoolbar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width,44)];
[backgrdtoolbar setBarStyle:UIBarStyleBlackOpaque];
[self.view addSubview:backgrdtoolbar];
mainScroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 45)];
[mainScroll setContentSize:CGSizeMake(600,45)];
[mainScroll setBackgroundColor:[UIColor clearColor]];
[mainScroll setShowsHorizontalScrollIndicator:NO];
mainToolbar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, 600, 44)];
[mainToolbar setBarStyle:UIBarStyleBlackTranslucent];
[self.view addSubview:mainScroll];
[mainScroll addSubview:mainToolbar];
UIBarButtonItem *b1 = [[UIBarButtonItem alloc]initWithTitle:@"1" style:UIBarButtonItemStyleBordered target:self action:@selector(_1:)];
UIBarButtonItem *b2 = [[UIBarButtonItem alloc]initWithTitle:@"2" style:UIBarButtonItemStyleBordered target:self action:@selector(_1:)];
UIBarButtonItem *b3 = [[UIBarButtonItem alloc]initWithTitle:@"3" style:UIBarButtonItemStyleBordered target:self action:@selector(_1:)];
UIBarButtonItem *spacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
NSMutableArray *arr = [[NSMutableArray alloc] initWithObjects:b1,spacer,b2,spacer,b3, spacer,b4,spacer,b5,spacer,b6,spacer,b7,spacer,b8,spacer,b9,spacer,b10,nil];
[mainToolbar setItems:arr];
}
- (IBAction)handle:(UIPanGestureRecognizer *)gesture {
static CGRect originalFrame;
if (gesture.state == UIGestureRecognizerStateBegan){
originalFrame = gesture.view.frame;
} else if (gesture.state == UIGestureRecognizerStateChanged) {
CGPoint translate = [gesture translationInView:gesture.view.superview];
CGRect newFrame = CGRectMake(fmin(gesture.view.superview.frame.size.width - originalFrame.size.width, fmax(originalFrame.origin.x + translate.x, 0.0)),
fmin(gesture.view.superview.frame.size.height - originalFrame.size.height, fmax(originalFrame.origin.y + translate.y , 0.0)),
originalFrame.size.width,
originalFrame.size.height);
gesture.view.frame = newFrame;
}
}