【发布时间】:2018-08-15 08:06:51
【问题描述】:
我有以下情节提要。 导航到 VC 类,我需要在 VC 顶部创建自定义按钮,我认为它将位于顶部导航栏控制器下方。如何使我的自定义按钮位于导航栏控制器的顶部并且可点击。我已经使顶部导航栏外观透明。
我有以下代码正在运行,布局在下面的图片 但这不是我想要的布局。它位于透明导航栏控制器区域下方的某个位置。
//--- customizeable button attributes
CGFloat X_BUFFER = 0.0; //--- the number of pixels on either side of the segment
CGFloat Y_BUFFER = 0.0; //--- number of pixels on top of the segment
CGFloat HEIGHT = 50.0; //--- height of the segment
//--- customizeable selector bar attributes (the black bar under the buttons)
CGFloat SELECTOR_Y_BUFFER = 0.0; //--- the y-value of the bar that shows what page you are on (0 is the top)
CGFloat SELECTOR_HEIGHT = 44.0; //--- thickness of the selector bar
CGFloat X_OFFSET = 8.0; //--- for some reason there's a little bit of a glitchy offset. I'm going to look for a better workaround in the future
CGFloat numControllers = 7.0;
-(void)setupSegmentButtons
{
navigationView = [[UIView alloc]initWithFrame:CGRectMake(0,0,self.view.frame.size.width,52)];
navigationView.backgroundColor = [UIColor greenColor];
[self.view addSubview:navigationView];
//——Format Some Dates
for (int i = 0; i<numControllers; i++) {
UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(i*(self.view.frame.size.width/numControllers), Y_BUFFER, (self.view.frame.size.width/numControllers),HEIGHT)];
[navigationView addSubview:button];
NSString *lblDate = [datelblFormat stringFromDate:[calendar dateFromComponents:comps]];
UILabel *firstLineButton = [[UILabel alloc] initWithFrame:CGRectMake(-4,0,self.view.frame.size.width/numControllers,30)];
firstLineButton.text = lblDate;
[button addSubview:firstLineButton];
NSString *lblDay = [daylblFormat stringFromDate:[calendar dateFromComponents:comps]];
UILabel *secondLineButton = [[UILabel alloc] initWithFrame:CGRectMake(-4,30,self.view.frame.size.width/numControllers,15)];
secondLineButton.text = lblDay;
[button addSubview:secondLineButton];
button.tag = i; //--- IMPORTANT: if you make your own custom buttons, you have to tag them appropriately
button.backgroundColor = [UIColor brownColor];//— buttoncolors
[button addTarget:self action:@selector(tapSegmentButtonAction:) forControlEvents:UIControlEventTouchUpInside];
++comps.day;
}
[self setupSelector];
}
//--- sets up the selection bar under the buttons on the navigation bar
-(void)setupSelector {
selectionBar = [[UIView alloc]initWithFrame:CGRectMake(self.view.frame.size.width/numControllers, Y_BUFFER, (self.view.frame.size.width/numControllers),HEIGHT)];
selectionBar.backgroundColor = [UIColor colorWithRed:189.0f/255.0f green:225.0f/255.0f blue:255.0f/255.0f alpha:0.6];
[navigationView addSubview:selectionBar];
}
我设法通过更改 Y 坐标将自定义按钮移动到顶部,我得到了以下结果。这并不理想,因为我需要棕色一直到手机边缘,尤其是 iPhoneX 和可点击的按钮。
【问题讨论】:
-
在标题路径中添加一个集合视图。
-
对不起,我是初学者,你能给我举几个例子吗?
-
据我了解这个问题,您希望棕色日期部分可点击吗?而且状态栏和旅游棕收藏部分应该是一样的吧?
-
是的,我想要可点击的棕色日期。而他的棕色会一直延伸到屏幕的边缘。状态栏仍然可见。
标签: ios objective-c uiview uinavigationcontroller uibutton