[英]Obj-C - How to add a menu bar on map
我想在圖像底部的地圖上創建一個菜單欄。 它的頂部有一個搜索欄,底部有三個按鈕。 如何將按鈕與圖片中的搜索欄連接起來? 謝謝你。
解決方案:
我跟着ezatu丶代碼做了一些改動:
`UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:searchBar.bounds byRoundingCorners:(UIRectCornerTopLeft | UIRectCornerTopRight)cornerRadii:CGSizeMake(6, 6)];
CAShapeLayer *maskLayer = [CAShapeLayer 圖層];
maskLayer.path = maskPath.CGPath;
searchBar.layer.mask = maskLayer;
[toolView addSubview:searchBar];` 創建圓角和陰影,同樣的代碼將按鈕放入for循環。
視圖的淺灰色背景。
帶有放大鏡圖像的 UITextfield 帶有以下代碼: UITextField *myTextField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, viewWidth, 40)]; myTextField.leftViewMode = UITextFieldViewModeAlways; myTextField.leftView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"asdf"]]; myTextField.backgroundColor = [UIColor whiteColor];
UITextField *myTextField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, viewWidth, 40)]; myTextField.leftViewMode = UITextFieldViewModeAlways; myTextField.leftView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"asdf"]]; myTextField.backgroundColor = [UIColor whiteColor];
而不是搜索欄。
感謝ezatu丶
您可以將自定義視圖添加到 self.view 並帶來視圖。
這是示例代碼:
#define SCREEN_WIDTH [UIScreen mainScreen].bounds.size.width
#define SCREEN_HEIGHT [UIScreen mainScreen].bounds.size.height
CGFloat margin = 10;
CGFloat viewWidth = self.view.frame.size.width - 2 * margin;
CGFloat viewHeight = 82;
UIView *toolView = [[UIView alloc] initWithFrame:CGRectMake(margin, SCREEN_HEIGHT - viewHeight - margin, viewWidth, viewHeight)];
toolView.backgroundColor = [UIColor grayColor];
UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, viewWidth, 40)];
[toolView addSubview:searchBar];
CGFloat btnWidth = (viewWidth - 4) / 3;
CGFloat btnHeight = 40;
for (NSInteger i = 0; i < 3; i ++) {
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
[btn setTitle:[NSString stringWithFormat:@"%ld btn", i+1] forState:UIControlStateNormal];
[toolView addSubview:btn];
[btn setBackgroundColor:[UIColor blackColor]];
btn.frame = CGRectMake(i *(btnWidth + 1), 42, btnWidth, btnHeight);
}
[self.view addSubview:toolView];
[self.view bringSubviewToFront:toolView];
您必須在地圖視圖控制器上添加視圖,您可以在其中添加所有按鈕和搜索欄。 並從情節提要中將搜索欄樣式設置為最小值。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.