Làm cách nào để xóa hiệu ứng bóng/bóng khỏi các nút trên thanh điều hướng? Nếu tôi tùy chỉnh thanh điều hướng bằng cách sử dụng hình ảnh tùy chỉnh, các nút không bị ảnh hưởng, tôi có thể xóa hiệu ứng khỏi chúng (dòng và độ bóng) hoặc xác định mã màu hex cho toàn bộ nút hoặc thậm chí là hình ảnh tùy chỉnh cho chúng quá?Loại bỏ hiệu ứng tỏa sáng khỏi các nút trong UINavigationBar
Trả lời
Tôi vừa trải qua quá trình tìm hiểu điều này. Về cơ bản, bạn cần tạo các hình ảnh có thể kéo giãn tùy chỉnh và sử dụng chúng làm nền của nút để loại bỏ độ sáng. Thay thế các nút quay lại trong một UINavigationController là một chút khó khăn hơn. Cho rằng tôi đã sử dụng một UINavigationControllerDelegate để thay thế nút quay lại mặc định bằng nút tùy chỉnh của tôi.
Dưới đây là một số mã:
Tạo một thể loại trên UIBarButtonItem tạo nút tùy chỉnh của bạn. Đây là của tôi. Tôi sử dụng loại này để tùy chỉnh cả hai nút thanh thường xuyên và trở lại nút:
@interface UIBarButtonItem (UIBarButtonItem_customBackground) + (id) customBarButtonWithTitle:(NSString *)title target:(id)target selector:(SEL)selector; + (id) customBackButtonWithTitle:(NSString *)title target:(id)target selector:(SEL)selector; @end @implementation UIBarButtonItem (UIBarButtonItem_customBackground) + (id) customButtonWithImageNamed:(NSString *)imageName selectedImageNamed:(NSString *)selectedImageName leftCapWidth:(CGFloat)leftCapWidth edgeInsets:(UIEdgeInsets)edgeInsets title:(NSString *)title target:(id)target selector:(SEL)selector { UIButton* customButton = [UIButton buttonWithType:UIButtonTypeCustom]; [customButton addTarget:target action:selector forControlEvents:UIControlEventTouchUpInside]; customButton.titleLabel.font = [UIFont boldSystemFontOfSize:12.0f]; customButton.titleLabel.shadowColor = [UIColor colorWithRed:0.0f/255.0f green:0.0f/255.0f blue:0.0f/255.0f alpha:0.25f]; customButton.titleLabel.shadowOffset = CGSizeMake(0.0f, -1.0f); customButton.titleLabel.lineBreakMode = UILineBreakModeTailTruncation; customButton.titleEdgeInsets = edgeInsets; UIImage* navButtonBackgroundImage = [[UIImage imageNamed:imageName] stretchableImageWithLeftCapWidth:leftCapWidth topCapHeight:0.0f]; UIImage* navButtonPressedBackgroundImage = [[UIImage imageNamed:selectedImageName] stretchableImageWithLeftCapWidth:leftCapWidth topCapHeight:0.0f]; [customButton setBackgroundImage:navButtonBackgroundImage forState:UIControlStateNormal]; [customButton setTitle:title forState:UIControlStateNormal]; [customButton setBackgroundImage:navButtonPressedBackgroundImage forState:UIControlStateHighlighted]; [customButton setBackgroundImage:navButtonPressedBackgroundImage forState:UIControlStateSelected]; CGSize size = CGSizeMake(30.0f, 30.0f); if (title != nil) { size = [[NSString stringWithString:title] sizeWithFont:customButton.titleLabel.font]; } customButton.frame = CGRectMake(0.0f, 0.0f, size.width + 20.0f, 30.0f); customButton.layer.shouldRasterize = YES; customButton.layer.rasterizationScale = [[UIScreen mainScreen] scale]; return [[[UIBarButtonItem alloc] initWithCustomView:customButton] autorelease]; } + (id) customBarButtonWithTitle:(NSString *)title target:(id)target selector:(SEL)selector { return [self customButtonWithImageNamed:@"navButtonBG.png" selectedImageNamed:@"navButtonPressedBG.png" leftCapWidth:6.0f edgeInsets:UIEdgeInsetsMake(0.0f, 5.0f, 0.0f, 5.0f) title:title target:target selector:selector]; } + (id) customBackButtonWithTitle:(NSString *)title target:(id)target selector:(SEL)selector { return [self customButtonWithImageNamed:@"backButtonBG.png" selectedImageNamed:@"backButtonPressedBG.png" leftCapWidth:12.0f edgeInsets:UIEdgeInsetsMake(0.0f, 11.0f, 0.0f, 5.0f) title:title target:target selector:selector]; } @end
Thêm nút để UINavigationBar
UIBarButtonItem* logoutButton = [UIBarButtonItem customBarButtonWithTitle:@"Logout" target:self selector:@selector(logout)]; self.navigationItem.rightBarButtonItem = logoutButton;
của bạn Nếu bạn cũng muốn thay thế nút lưng UINavigationController, thiết lập một UINavigationControllerDelegate và triển khai phương thức willShowViewController như sau:
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated { if([navigationController.viewControllers count ] > 1) { UIViewController* backViewController = [navigationController.viewControllers objectAtIndex:(navigationController.viewControllers.count - 2)]; NSString* backText = backViewController.title; UIBarButtonItem* newBackButton = [UIBarButtonItem customBackButtonWithTitle:backText target:navigationController selector:@selector(popViewControllerAnimated:)]; viewController.navigationItem.leftBarButtonItem = newBackButton; viewController.navigationItem.hidesBackButton = YES; } }
Đây là stretc hình ảnh hable Tôi đang sử dụng:
- Trở lại nút: Pressed:
- nút thường xuyên: Pressed:
BẠN. LÀ VÌ THẾ. FEAKING. TUYỆT VỜI!!!!! Anh yêu em! – Eugene
@Justin Gallagher Justin cảm ơn bạn cảm ơn bạn cảm ơn bạn! –
Làm cách nào để thêm mã này vào một dự án để sử dụng? –
bạn phải sử dụng nút tùy chỉnh có hình ảnh mà không có bất kỳ hiệu ứng bóng nào trên hình ảnh mà bạn có thể loại bỏ hiệu ứng gloos của nút từ thanh điều hướng.
Đối với việc thay đổi nút quay lại nó không phải là cần thiết để thực hiện các uinavigationcontroller phương pháp đại biểu.
Bạn chỉ cần đặt thuộc tính hidesBAckButton thành YES sau khi đặt nút back mong muốn như @Justin Gallacher giải thích một cách hoàn hảo.
self.navigationItem.leftBarButtonItem = [UIBarButtonItem customBackButtonWithTitle:@"Back" target:self.navigationController selector:@selector(popViewControllerAnimated:)];
self.navigationItem.hidesBackButton = YES;
Điều này thậm chí không cần thiết, thiết lập thuộc tính leftBarButtonItem sẽ ghi đè nút quay lại – Daniel
- 1. Làm thế nào để loại bỏ hiệu ứng chuột mặc định trên các nút WPF?
- 2. Hiệu ứng phát sáng bên trong của nút
- 3. Hoạt ảnh văn bản từ trái sang phải như tỏa sáng trong Android
- 4. iOS 5 UINavigationBar loại bỏ subviews (hình ảnh subview) loại bỏ thanh điều hướng
- 5. UINavigationBar với các nút làm tiêu đề.
- 6. Loại bỏ đường viền nút trong WPF?
- 7. nút Loại bỏ từ XDocument
- 8. Ẩn tiêu đề khỏi UINavigationBar?
- 9. Loại bỏ các nút rỗng từ HTML
- 10. Loại bỏ dòng mới khỏi các lệnh shell trong Ruby
- 11. WPF ListView loại bỏ hiệu ứng di chuột
- 12. Loại bỏ hiệu ứng Bevel ở góc biên giới
- 13. Cách thêm nút vào UINavigationBar?
- 14. Loại bỏ hiệu ứng bóng nảy trên slidetoggle
- 15. iPhone: UINavigationBar bằng các nút - điều chỉnh chiều cao
- 16. Làm thế nào để loại bỏ các ràng buộc từ nút trong loại trực tiếp?
- 17. Làm thế nào để loại bỏ tiếng ồn chiếu sáng?
- 18. Loại bỏ các đối tượng khỏi một lớp bằng KineticJS
- 19. MongoDB loại bỏ các đối tượng GridFS khỏi shell
- 20. CSS: Cách tạo các nút có ánh sáng phản chiếu tương tự như biểu tượng iOS?
- 21. jqGrid loại bỏ các tiêu đề cột khỏi lưới con
- 22. Loại bỏ các đối tượng stdClass khỏi mảng
- 23. Cách thay đổi màu chữ trên các mục nút UINavigationBar
- 24. Loại bỏ các hàng trống liên tiếp khỏi StringBuilder
- 25. Loại bỏ - Xóa mục khỏi ViewModel không xóa khỏi DOM
- 26. Nút HTML Hiệu ứng "Đẩy"
- 27. Làm thế nào để loại bỏ nút chết ra khỏi cụm Cassandra?
- 28. Tạo hiệu ứng đồ họa/bóng sáng bóng
- 29. Tạo hiệu ứng văn bản phát sáng trên iOS
- 30. Trình định dạng mã Eclipse: làm thế nào để loại bỏ các hiệu ứng của nó?
@Rudy - Nếu bạn cho rằng câu hỏi là trùng lặp với một câu hỏi khác, vui lòng bỏ phiếu để đóng câu hỏi thay vì chỉnh sửa nội dung của câu hỏi. –
Đây là bản sao có thể có của [iOS: Cách thay thế nền của thanh tìm kiếm tỏa sáng/phát sáng bằng một màu] (http://stackoverflow.com/questions/6696200/ios-how-to-replace-search-bar-background- tỏa sáng rực rỡ với một màu) –