Want to have view as Image Attached using UITableView - iphone

Hi
In my app, i have a requirement to make this grid view..type....i want to do it by UITableView...(Although done via scroll view)
My Query is , by using custom cell, in 1 row, there will be 1 custom cell with 4 image view in it...
so now on image tapping how will i know which image inside cell is tapped????
or second option i thought..as each image as custom cell..but dont know how to proceed furthur....as how can we get 2 adjacent cell in 1 row????
Also wanna know which method is better...as this grid view will be containing 50 images around....and on tapping bigger view opens with scrolling...
Thanks

What you can do is create a custom UIButton inside the UIView and set a background image and a selector.
Something like this :
UIButton *button = [[UIButton buttonWithType:UIButtonTypeCustom] initWithFrame:CGRectMake(0, 0, 24, 24)];
[button addTarget:self action:#selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
[button setBackgroundImage:[UIImage imageNamed:#"someImage.png"] forState:UIControlStateNormal];
[buttonHolder addSubview:button]; //buttonHolder will be one of the UIView in your cell

i have create image gallery view using scroll view gallery view
if you want to make in table view you have to create custom cell with 4 image view and a single button each image attached with image tag when a button pressed it get the tag number and you can find which of image button is clicked.

Related

How to select and deselect the thumbnail images in iphone

I am new to i phone programming.How to select and deselect the thumbnail images.Right now what i did i have taken custom button using that i am adding custom image to thumbnails,it is mainly used for i can know that these thumbnail images are selected.like that,if select any thumbnail image means,custom button is attaching to each every selected thumbnail image.
Now what i want means if i again click on same image means i want remove custom button image form the selected thumbnail.again if i selected means it have attach that custom button image and if again select on same image means i have remove that custom button image form the thumbnail.Can any body tell what logic i have use here.
Here is my code
- (void)handleThumbClick:(id)sender
{
NSLog(#"yes selected");
FGalleryPhotoView *photoView = (FGalleryPhotoView*)[(UIButton*)sender superview];
customBadge1 = [CustomBadge customBadgeWithString:#"1"
withStringColor:[UIColor greenColor]
withInsetColor:[UIColor redColor]
withBadgeFrame:YES
withBadgeFrameColor:[UIColor grayColor]
withScale:1.0
withShining:YES];
b =[UIButton buttonWithType:UIButtonTypeCustom];
b.frame = CGRectMake(0,0, 100,100);
[b setImage:[UIImage imageNamed:#"Overlay#2x.png"] forState:UIControlStateNormal];
[b setTitle:#"1" forState:UIControlStateNormal];
// [b setTag:4];
NSLog(#"Thumb click Fgallerview controller");
[photoView addSubview:b];
[photoView addSubview:customBadge1];
}
The above code for if click on any thumbnail means its attaching the custom button image to that thumbnail image.Now what i want means if again if click on same thumbnail i have remove that custom thumbnail image.
For example in thumbnail view i have 10 images is displaying now i want to select only 5 images if click on any 5 thumbnail means its attaching custom button image to 5 selected images.Now what i want means if want in selected 5 thumbnail images having custom button image.now if i select any selected image means i have to uncheck that selected image ,means i want to remove that custom button image form the selected thumbnail.
Can any body tell me how to do this
And one more thing i now that by using ELCimagepickercontroller we can able to select multiple images,but that only gallery images but here i am displaying from private document directory folder images..Please help meee
Thanks
Aslam
Set thumbnail image as setBackgroundImage and set initial tag=0;
-(IBAction)handleThumbClick:(id)sender
{
UIButton *btn = (UIButton*)sender;
if (btn.tag==0)
{
[btn setImage:[UIImage imageNamed:#"Default.png"] forState:UIControlStateNormal];
btn.tag=1;
}
else{
[btn setImage:nil forState:UIControlStateNormal];
btn.tag=0;
}
}

Custom UIButton image iOS

Is it possible to have a custom UIButton that has an image covering only half of it?
I imagine it would be something like this:
UIButton *someButton = [UIButton buttonWithType:UIButtonTypeCustom];
[someButton setBackgroundImage:[UIImage imageNamed:#"buttonPicture"]];
/* Then there must be some property I can set that prevents the button from stretching the image?? */
.
.
.
I want to have a 50x100px button which only has a 50x50px image on the top half, and to be transparent on the bottom half.
I know how to create a custom button and everything. Im just woondering what the property is that controls the stretching of the backgroundImage.
Thanks!
Use
[someButton setImage:[UIImage imageNamed:#"buttonPicture"] forState: UIControlStateNormal];
someButton.imageEdgeInsets = UIEdgeInsetsMake(-50, 0, 0, 0);
I think you could:
create your button image as a 50x100px image (same size as the button);
make this image be half transparent (PNG with alpha),
instead of trying to assign the button a smaller image covering only half of it and prevent stretching.

iPhone: How to make UIButton which you can easily tap?

I'm making customized navigation bar by using UIView and UIButtons instead of UINavigationBar.
But my UIButtons on the navigation bar doesn't response sensitively.
I have to tap almost center of the UIButton to tap.
It doesn't respond if I tap edge of the UIButton.
But buttons on normal UINavigationBar can be tapped by tapping edge of the button.
Even by tapping outside of the button, it can be tapped.
Shutter button or Option button on the camera app also can be tapped by tapping edge or outside of buttons.
How can I implement those easily tappable buttons to my app?
Use an image and create a custom button. Set the button so the image does not scale to the size of the button's view, but instead will just Center. Expand the button's size so it is larger than the image on each side. Apple does this as well with things like tab buttons.
UIButton has an imageEdgeInsets property specially for this purpose. Just make a UIButton frame as big as you need for touchable area and than scale image inside it appropriately, using imageEdgeInsets.
Disclaimer: This code has not been tested, but it gives you an idea of how it could be done.
You make a button (in this case 40px x 40px), and then add a background image to it which is smaller, hence gives the impression of that the image is very "clickable".
// This image is 20px x 20px (Just an example)
UIImage* backgroundImage = UIImage imageNamed:#"backgroundImage.png"]
// Custom button, remember to add a target method
UIButton* customButton = [UIButton buttonWithType:UIButtonTypeCustom];
customButton.frame = CGRectMake(0.0, 0.0, 40.0, 40.0);
customButton.contentMode = UIViewContentModeCenter;
[customButton setImage:backgroundImage forState:UIControlStateNormal];
UIBarButtonItem* customBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:customButton];
self.navigationItem.rightBarButtonItem = customBarButtonItem;
[customBarButtonItem release];

iPhone UITextField and UIButton in one grey frame

I would like to create something like this:
I would like to place an UITextField with an UIButton into one grey frame, and I would like the button's border to be contained by this grey frame.
Please somebody show me some sample code for this!
Thx!
1. Use a UIImageView of required rect. Set the background image to the gradient gray colour image.
UIImageView*myImageView=[[UIImageView alloc] initWithFrame:yourFrame];
[myImageView setImage:[UIImage imageNamed:#"grayBackground.png"];
[self.view addSubview:myImageView];
2. Use a round rect. UITextField make it a subview of the image view. Use a place holder as "Write a reply..." make it a subview to your imageview.
UITextField*myField=[[UITextField alloc] initWithFrame:yourRect];
[myField setBorderStyle:UITextBorderStyleRoundedRect];
[myField setPlaceholder:#"Write a reply..."];
[myImageView addSubview:myField];
3. Use a UIButton with type Custom and the send image as its background image, make it a subview to your imageview.
UIButton*myButton=[UIButton buttonWithType:UIButtonTypeCustom];
[myButton setFrame:yourRect]
[myButton setBackgroundImage:[UIImage imageNamed:#"sendImage.png"] forState:UIControlStateNormal];
[myImageView addSubView:myButton];
Simple way is to create title bar with grey background and delete the title.and place textfield and button which u want to place it.configure the size and button outside the title bar and drag it to the title bar..u'll get like the image which u have got.

How can i put UITableViewCellEditingStyleInsert on the right?

I want to know how can i put UITableViewCellEditingStyleInsert on the right in UITableView like in this picture:
You can create a UIButton with the type UIButtonTypeContactAdd and add it as an accessory view:
UIButton *accessory = [UIButton buttonWithType:UIButtonTypeContactAdd];
[cell setAccessoryView:accessory];
The icon is blue, though; if you want it to be green like UITableViewCellEditingStyleInsert, you have to make a button with a custom image instead of using UIButtonTypeContactAdd.