How to set a image on Navigation right bar button item? - uinavigationcontroller

i want to set a navigation controller's right bar button item to image so i write a code like as
UIImageView *image = [[UIImageView alloc]initWithImage:[UIImage imageNamed:#"Button.png"]];
image.frame=CGRectMake(0, 25, 35, 40);
UIBarButtonItem *customButton = [[UIBarButtonItem alloc]initWithCustomView:image];
customButton.title=[NSString stringWithFormat:#"Hi"];
[customButton setImage:[UIImage imageNamed:#"Button.png"]];
it is like as i want but then button was not clickable.any solution for that????

Related

Placing buttons on opposite sides of an adjustable window in JavaFX

I have two buttons that I'd like to use in my display screen: a reset button, and a settings button.
The problem is, I want them on opposite sides of the window (reset in the top right corner and settings in the top left) while being the same height. When I expand the window, however, the buttons stay in the same place, but I want them to move with the window walls.
I first tried using setAlignment of my reset button to Pos.*TOP_RIGHT* and the settings button to top left, but it comes out with the settings button being on top of the reset button.
resetButton = new Button("Reset Gameboard");this.setTop(resetButton);
resetBox = new HBox(resetButton);
resetBox.setAlignment(Pos.TOP_RIGHT);
backButton = new Button("Back to Settings");
this.setTop(backButton);
backBox = new HBox(backButton);
backBox.setAlignment(Pos.TOP_LEFT);
resetbackBox = new HBox(backButton, resetButton);
this.setTop(resetbackBox);`
I currently am using (below) which during the initial window appears to be working and correctly spaced, but as soon as you expand the window the reset button doesn't follow it, although the settings button does.
`resetButton = new Button("Reset Gameboard");
this.setTop(resetButton);
resetBox = new HBox(resetButton);
resetBox.setAlignment(Pos.TOP_RIGHT);
backButton = new Button("Back to Settings");
this.setTop(backButton);
backBox = new HBox(backButton);
backBox.setAlignment(Pos.TOP_LEFT);
resetbackBox = new HBox(backButton, resetButton);
resetbackBox.setSpacing(380);
this.setTop(resetbackBox);`
The problem start from this line:
resetbackBox.setSpacing(380);
You have setted a fixed spacing value. To fix that you can easily add a component to HBox called Region, this component allow to set a grow area between two buttons:
Button resetButton = new Button("Reset Gameboard");
Button backButton = new Button("Back to Settings");
Region region = new Region();
HBox.setHgrow(region, Priority.ALWAYS);
HBox topHBox = new HBox(backButton, region, resetButton);
this.setTop(resetbackBox);

Display big image in QListWidget

I want to use QListWidget to display big images, e.g. 3508×4961 size in pixels, each list item will display one image. The image is set in a Qlabel and the Qlabel is set into the QListWidgetItem by setItemWidget(). When my program is running, the list item cannot display the entire image because the image is too large. It only displays the upper part of an image. When I scroll down, the list item changes to the next image immediately instead of showing the lower part of the current image gradually. Does anyone know how to show the lower part of each image by scrolling?
Here is my code,
QImage *image = new QImage("/home/sk/image1.png");
QLabel *label = new QLabel;
label->setPixmap(QPixmap(QPixmap::fromImage(*image)));
QListWidgetItem *ite = new QListWidgetItem;
auto size = label->sizeHint();
ite->setSizeHint(label->sizeHint());
size = ite->sizeHint();
ui->listWidget->addItem(ite);
ui->listWidget->setItemWidget(ite, label);
image = new QImage("/home/sk/image2.png");
label = new QLabel;
label->setPixmap(QPixmap(QPixmap::fromImage(*image)));
ite = new QListWidgetItem;
ite->setSizeHint(label->sizeHint());
ui->listWidget->addItem(ite);
ui->listWidget->setItemWidget(ite, label);
image = new QImage("/home/sk/image3.png");
label = new QLabel;
label->setPixmap(QPixmap(QPixmap::fromImage(*image)));
ite = new QListWidgetItem;
ite->setSizeHint(label->sizeHint());
ui->listWidget->addItem(ite);
ui->listWidget->setItemWidget(ite, label);
have you tried changing the scroll mode to ScrollPerPixel
setVerticalScrollMode
and
setHorizontalScrollMode
ui->listWidget->setVerticalScrollMode(QListWidget::ScrollPerPixel);
and in order to change the scroll step
ui->listWidget->verticalScrollBar()->setSingleStep(10);
ui->listWidget->verticalScrollBar()->setPageStep(20);
these values will be used for scrolling

Layering in iOS (6)

In my app the user is able to drag a few images, those appear when he presses a button. The problem is that when I drag the UIImageView over the button and release it then I can not touch / drag the image anymore because the button is on top of it though the image is optically over the button.
So: how can I put the button in the background and the image over it?
so this is to create the UIImageView on touch.
- (IBAction)SchiffRotButton:(id)sender {
NSLog(#"setting schiffrot.png...");
[_SchiffRotImageView setImage:[UIImage imageNamed:#"schiffrot.png"]]; }
this is the button itself:
UIButton *SchiffRotBuztton = [UIButton buttonWithType:UIButtonTypeCustom];
SchiffRotBuztton.frame = CGRectMake(198, 646, 59, 59);
[UIImage imageNamed:#"schifffeldrot.png"];
by this i move the image:
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
printf("touch moved \n");
UITouch *myTouch = [touches anyObject];
startPoint = [myTouch locationInView:self.view];
if ([_whichPiece isEqualToString:#"SchiffGelbImageView"])
{
_SchiffGelbImageView.center = CGPointMake(startPoint.x, startPoint.y);
}
thanks for your help
LiGe

Set Different Navation bar title for different View controller in iphone

I have navigation bar i am setting title on image which is used in navigation bar it works fine but when i use same code for other controller it shows same previous title on navigation bar not the new one.
here is the code
UIImage *image = [UIImage imageNamed:#"Nav.png"];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
[self.navigationController.navigationBar addSubview:imageView];
titleLabel=[[UILabel alloc] initWithFrame:CGRectMake(50,2,250,36)];
titleLabel.text=#"Activity";
titleLabel.textColor=[UIColor whiteColor];
titleLabel.backgroundColor=[UIColor clearColor];
titleLabel.font=[UIFont fontWithName:#"Helvetica-Bold" size :18];
[self.navigationController.navigationBar addSubview:titleLabel];

How to set correct coordinates for UIImageView to UINavigationController using CGRect?

imgView1 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 360, 44)];
[imgView1 setImage:[UIImage imageNamed:#"bg.png"]];
self.navigationItem.titleView = imgView1;
My problem here is that Image on NavigationBar has some blabnk space at left side corner and its looking bad. So i wanna make the Image displayed on whole Navigation Bar and also if any buttons on Navigation Bar then image should come backgroud.

Resources