English 中文(简体)
在目标c中导航条标上的形象
原标题:image in title of navigation bar in objective c

我已提出“iPad”申请,因为我使用了导航控制,

现在,在标题栏中,我想把图像放在左边,因此,我隐藏着带有标签的头衔,但标签并不涵盖整个所有权条形,

IL App in the SCREEN SHOT,

这里是法典,

UILabel *titleView = (UILabel *)self.navigationItem.titleView;
    if (!titleView) {
        titleView = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 800, 50)];
        titleView.backgroundColor = [UIColor clearColor];
        titleView.font = [UIFont boldSystemFontOfSize:20.0];
        titleView.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.5];

        titleView.textColor = [UIColor yellowColor]; // Change to desired color


        titleView.backgroundColor=[UIColor blackColor];

        titleView.text = @"IL APP";
        titleView.textAlignment=UITextAlignmentCenter;
        //self.navigationItem.titleView = titleView;
        [self.navigationItem setTitleView:titleView];
        [titleView release];
    }

“cr”/

最佳回答

@Gama as far as your question is concerned you are asking to put an Image but your real issue being described is that the label is not covering up the title bar. To cover that properly you can use

UILabel *titleView = (UILabel *)self.navigationItem.titleView;
if (!titleView) {
    titleView = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 32)];
    titleView.backgroundColor = [UIColor clearColor];
    titleView.font = [UIFont boldSystemFontOfSize:20.0];
    titleView.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.5];
    titleView.textColor = [UIColor yellowColor]; // Change to desired color
    //titleView.backgroundColor=[UIColor blackColor];
    titleView.text = @"IL APP";
    titleView.textAlignment=UITextAlignmentCenter;
    [self.navigationItem setTitleView:titleView];
    [titleView release];
}
[self.navigationController.navigationBar setTintColor:[UIColor blackColor]];

在使用图像时,你可以使用图像观点,而不是作为标题的标签。 航行观点 项目。

希望会有助于

问题回答

我试图解决你的问题,但我也取得了同样的结果。

但是,你可以躲藏导航条码,并在<条码>上添加<条码>。

self.navigationController.navigationBarHidden = FALSE;
[self.view addSubview:titleview];

UIImageView *imageNav = [[UIImageView alloc] initWithImage: [UIImage imageNamed: @"navImage.png"]];
[self.navigationController.navigationBar addSubview:imagenav];

[self.navigationController.navigationBar sendSubviewToBack:imageNav];
[imageNav release];

然而,我也想做同样的事情,我看到你就职,即基本上使用你提供的一些法典,并对它做了些什么修改,并做如下工作:

//declare and initialize your imageView
UIImageView *titleImage = (UIImageView *)self.navigationItem.titleView;

titleImage = [[UIImageView alloc] 
initWithFrame:CGRectMake((self.navigationController.navigationBar.frame.size.width/2) 
- (100/2), 0, 100, self.navigationController.navigationBar.frame.size.height)];

//setting the image for UIImageView
titleImage.image = [UIImage imageName:@"photo.jpg"];

页: 1

self.navigationItem.titleView = titleImage;




相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签