我正在开发一个需要自定义 uinavigationbar 的项目。所需的效果是对包含在导航控制器中的视图堆栈进行可视化。
想象一下,对于您向前移动的每个视图,导航栏中都会出现一个新按钮,用于您刚刚离开的视图,例如
查看 1 >> 查看 2 >> 查看 3
我很擅长创建自定义的可重用 iOS 组件,但我很想听听其他人如何处理这项任务。
我现在运行的实例是 UIView 的子视图,在初始化时,我通过为委托类提供的字典数组中详细说明的条目添加 UIButtons 创建导航栏。
在伪代码中:
@protocol NavDelegate
- (void)UIButtonClicked;
@end
@protocol NavDataSource
- (NSMutableArray *)arrayOfDictionaries;
@end
@interface Navbar : UIView
<NavDelegate,NavDataSource>
{
//create and synthesize delegate and datasource objects
}
@end
@implementation NavBar
- (id)init
{
//override and instantiate necessary objects
}
- (void)layoutSubviews
{
//here I use the number of dictionaries in the delegate returned array to add UIButtons to
//a UIView adding control events for when the button is clicked
}
@end
它有效,但我不禁觉得那里有一个更优雅的解决方案。
我也很想知道人们是否认为这是一种应该避免的做法。我一直不愿意“重新发明轮子”,但项目利益相关者认为这是一个很好的 UI 元素。如果舆论的潮流是“不惜一切代价避免”,那么我肯定会把这个论点放回他们身上。
提前谢谢各位