我正在为具有相机按钮、文本字段和发送按钮的小型聊天应用程序创建自定义工具栏。所有功能都可以正常工作,但我一直在尝试获取“发送”按钮的位置。
相机按钮需要在左侧对齐,而发送按钮需要在右侧对齐。
我正在完成这项工作,但无法让发送按钮正确对齐到右侧,我似乎无法将它移动到比现在更远的位置。
我尝试了灵活间距和固定间距(目前在我的代码片段中),但没有成功。
NSString *imageValue = @"btnCamera.png";
UIImage *cameraImage = [UIImage imageNamed:imageValue];
UIButton *cameraButton = [UIButton buttonWithType:UIButtonTypeCustom];
cameraButton.bounds = CGRectMake(0, 0, 30, 49);
[cameraButton setImage:cameraImage forState:UIControlStateNormal];
UIBarButtonItem *cameraItem = [[UIBarButtonItem alloc] initWithCustomView:cameraButton];
[cameraButton addTarget:self
action:@selector(inputCamButtonPressed)
forControlEvents:UIControlEventTouchUpInside];
NSMutableArray *items = [[NSMutableArray alloc] init];
UIBarButtonItem *spacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
spacer.width = -12;
[items addObject:spacer];
[items addObject:cameraItem];
UIBarButtonItem *fixedItemSpaceWidth = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = screenRect.size.height;
fixedItemSpaceWidth.width = screenWidth - 90;
[items addObject:fixedItemSpaceWidth];
imageValue = @"send.png";
UIImage *sendImage = [UIImage imageNamed:imageValue];
UIButton *sendButton = [UIButton buttonWithType:UIButtonTypeCustom];
sendButton.enabled = NO;
sendButton.tintColor = [UIColor blackColor];
sendButton.bounds = CGRectMake(0, 0, 30, 49);
[sendButton setImage:sendImage forState:UIControlStateNormal];
UIBarButtonItem *sendItem = [[UIBarButtonItem alloc] initWithCustomView:sendButton];
sendItem.tintColor = [UIColor blackColor];
/* Create UIExpandingTextView input */
self.textView = [[BHExpandingTextView alloc] initWithFrame:CGRectMake(40, 7, self.bounds.size.width - 70, 26)];
self.textView.internalTextView.scrollIndicatorInsets = UIEdgeInsetsMake(4.0f, 0.0f, 10.0f, 0.0f);
self.textView.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth;
self.textView.delegate = self;
[self addSubview:self.textView];
[self setItems:items animated:NO];
希望有人能够发现我犯的最有可能犯的愚蠢的小错误,并且无法绕过。