如何在目标c中为CAPSPageMenu设置UIView的图像标题

时间:2016-06-14 06:27:42

标签: ios

我是IOS的新手并创建了一款应用。 我使用CAPSPageMenu页面菜单.Menu工作正常,但我想改变 标题作为图像。我搜索了很多,但都是消极的。

Thread t=new Thread(new Runnable () {
    public void run () {
        System.out.println(Thread.currentThread().getName());
    }
});

enter image description here

PLUSr是一个演示标题,我想在图像中更改它。提前谢谢。

4 个答案:

答案 0 :(得分:0)

#pragma mark: - 导航栏

-(void)createCustomNavBar
{

UIView *topBarView =[[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 44)];
topBarView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0];
[self.view addSubview:topBarView];


UIButton *btnBack = [[UIButton alloc]initWithFrame:CGRectMake(2.5, 0, 44, 44)];
[btnBack setImage:[UIImage imageNamed:@"backs_icon_iPhone.png"] forState:UIControlStateNormal];
[btnBack addTarget:self action:@selector(backButtonAction) forControlEvents:UIControlEventTouchUpInside];
[topBarView addSubview:btnBack];

UIImageView *titleImageView=[[UIImageView alloc]init];
titleImageView.image= [UIImage imageNamed:@"sample.png"];
titleImageView.frame=CGRectMake(80, 0, SCREEN_WIDTH-160, 44);
[topBarView addSubview:titleImageView];

}

这是解决方案之一。调用这个createCustomNavBar mathod。感谢

答案 1 :(得分:0)

您可以将图像设置为控制器的标题,如下面的代码

首先,您需要嵌入Navigation Controller以便在控制器上导航,然后在该控制器的viewDidLoad方法中编写下面的代码

 UIImage *image = [[UIImage alloc]initWithName:@"YOUR_IMAGE"];
 UIImageView *imageView = [[UIImageView alloc]init];
 imageView.image = image;
 self.navigationItem.titleView = imageView;

希望这会对你有所帮助:)。

注意:我在Swift中这样做但是如果对obj-c进行任何更正,那么请更改它。

答案 2 :(得分:0)

Navigationitem有titleView属性,可用于在导航视图中设置自定义视图。

您可以创建一个这样的方法并调用viewDidLoad。

-(void)setTitleViewForNavigation {
    self.navigationController.navigationBar.backgroundColor =[UIColor blueColor];
    UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 200, 44)];
        [imageView setImage:[UIImage imageNamed:@"placeholder"]];
    imageView.backgroundColor = [UIColor redColor];
    self.navigationItem.titleView = imageView;
    [self.navigationItem setTitleView:imageView];
}

答案 3 :(得分:0)

使用:
 CAPSPageMenuOptionScrollMenuBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"yourImage"]