请支持原创, 如需转载, 请注明出处@TEASON
UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"user"] style:UIBarButtonItemStylePlain target:self action:@selector(leftButtonClicked)] ;
animation
需要添加在layer
上, layer可以是单独存在, 也可以是view的子类.
利用UIBarButtonItem
的initWithCustomView:
方法. 生成一个自定义视图. 操作这个自定义视图, (当然, 你可以设置他为成员变量)
m_shareImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, btSide, btSide)] ;
m_shareImage.image = [UIImage imageNamed:@"share"] ;
m_shareImage.contentMode = UIViewContentModeScaleAspectFit ;
UIButton *btShare = [[UIButton alloc] init] ;
btShare.bounds = m_shareImage.bounds ;
[btShare addSubview:m_shareImage] ;
[btShare addTarget:self action:@selector(rightButtonClicked) forControlEvents:UIControlEventTouchUpInside] ;
UIBarButtonItem *shareItem = [[UIBarButtonItem alloc] initWithCustomView:btShare] ;
so that's it .