How can I reproduce the standard header for a plain UITableView - iphone

I have a plain UITableView in my iPhoneApp. I would like to change the font size of the header text.
I understand that this is not possible and that I need to create my custom header with my own label.
I just wonder if anybody knows how I can reproduce a header similar to the standard one (using the same background image,etc...)? I can not find the background image anywhere..
Best regards,
Jonathan

You're looking for [UIColor groupTableViewBackgroundColor]:
[view setBackgroundColor:[UIColor groupTableViewBackgroundColor]];

It won't stretch REALLY high, because it will look bad, but this can get you out of dodge, create a stretchable image which uses a graphic of the original header (any iphone template png/psd has these readily extractable).
Then
UIImage *image = [UIImage imageNamed:#"tableHeader.png"];
UIImage *stretchImage = [image stretchableImageWithLeftCapWidth:5.0 topCapHeight:2.0];
UIImageView *backgroundImage = [[UIImageView alloc] initWithFrame:frame];
[backgroundImage setImage:stretchImage];
and either return that as part of the UIView you construct in your:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
method or (better still) add it as the background of whatever UIView subclass instance you're returning in that method.
Clearly, any width works, I've found I can get it up to 55pixels high without looking naff. Best answer is to replicate the gradient.. I'm too nooby for that though :)

Related

Expandable UITextField with option for inserting image

I want to make the same view as iPhone default message app here is the screen shot what i want to do so can any one help me for suggesting 3rd party control or technique for making this kind of control in my app
Here is the Source code you wanted for the Growing TextField , although it doesn't contains the image button but you can easily customize it to fullfil your requirement
https://github.com/HansPinckaers/GrowingTextView
Hope it will help you.
You can add the image view as a subView of UITextView.
Create an imageView with image:
UIImageView *imageView = [[UIImageView alloc] initWithImage:yourImage];
[imageView setFrame:yourFrame];
[yourTextView addSubview:imageView];
and can use third party library for this Here
Hope it helps you.
you can directly add your image view on text view.
Tried this one
UIImageView * image=[[UIImageView alloc]initWithImage:[UIImage imageNamed:#"xyz.png"]];
[textview addSubview:image];
this will really helpful.

iOS Background Image doesn't display properly?

I've literally piled through hundreds go searches on google :(. I can't seem to figure out what I'm doing wrong when I create an image in photoshop (960 x 600, -40 for the status bar). The image comes out to this:
When it should look like this:
(note this is not the actually size, crappy thumbnail version :P. The size is as stated above)
This is my code:
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"MenuBkground.png"]];
Am I doing something wrong when I make the image? Is it in the code? Any ideas?
You're using colorWithPatternImage which basically means what it says. The image will repeat itself if the space is not entirely consumed by the image. If you want to have a true background image you should create the image as a subview.
UIImage* image = [UIImage imageNamed:#"MenuBKground.png"];
UIImageView* background = [[UIImageView alloc]initWithImage: image];
[self.view addSubview: background];
Another way if your using interface builder,
Drag an image view to your viewController.
Assign that as MenuBkground.png in the inspector (first drop down box)

UIImage UITableViewCell

How can I pass an image that is in my UITableViewCell to my TableDetailsView.
I tried setting the data on Post, which is my type of data that fills the UITableView cells.
[[cell avatar] setImage:[UIImage imageNamed:#"butterfly.jpeg"]];
[post setImage: [UIImage imageNamed:#"butterfly.jpeg"]]; <-- app crashes here.
All it seems that Question still is not complete....
But looking at two lines of code & you want to pass an image then you could do this thing in lots of ways.
so for testing purpose I will suggest ,just use a Global String i.e in Delegate.
like.Otherwise can you can use this link for Global Variable
Pass a variable between lots of UIVIewControllers
DelegateClassObj.yourGlobalString = [NSString stringwithFormat:#"%#",#"butterfly.jpeg"];
from the class where you want to pass.
&
now if you want to use it:
Suppose post in your imageView then
[post setImage: [UIImage imageNamed:DelegateClassObj.yourGlobalString]];
Hope this will work....the easir way :)
If Your motive is to Display same Image on detail view, then you can pass the name (or Id) of that image on cell tap. and load that image in your detail view through that.

If I create a PNG image in photoshop with 85% opacity, how can I maintain that same level of opacity when I add it to my iOS app?

If I create a PNG image in Photoshop and lower the opacity so it's 85% opaque, how can I maintain that same level of transparency when I add it to my iOS app?
I'm trying to set the background image of a UILabel to be this image, but the background image for the UILabel is fully opaque in my iOS app. Here's my code...
[lbl setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:#"labelBackground.png"]]];
Am I missing something or is this not possible?
Thanks so much for your wisdom!
If I were you, I'd put an UIImageView containing the image behind your UILabel. Then make sure your UILabel and UIImageView backgroundColors are both set to [UIColor clearColor]. That's how I do it anyway.
Have you tried lbl.opaque = NO;?
From my experience, iOS preserves opacity for PNG images.
I think I have an idea of what MAY be wrong (and pardon me for making any wrong assumptions)...
In photoshop, when saving a PNG image, there's an option to "Save Transparency" or something like that. Make sure that is checked before you save the PNG.
If this is not the problem, you can always use:
UIImageView.opacity = 85.0f/100.0f;
Let me know if this solves your problem :)
I ran into some background issues just like you, but I learned that most UIView subclasses have a backgroundView property which is accessed like this:
[aView backgroundView];
or
aView.backgroundView = someView;
UIImageViews keep the opacity of images. With these two things in mind you can just do:
UIImageView *imageView = [UIImageView initWithImage:[UIImage imageNamed:#"YourImage.png"]];
myLabel.backgroundColor = [UIColor clearColor];
myLabel.backgroundView = imageView;
I hope you find this useful.

iPhone - user interaction with programmatically added UIImageView

So I'm trying to add UIImageViews programatically (in this case I don't have the option of doing it in IB) and I want to be able to refer to them and manipulate them in the -touchesBegan and -touchesMoved methods.
I've added the images like this:
UIImageView *newPiece = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:#"%d.png", [piece tag]]]];
newPiece.frame = CGRectMake(pieceX, pieceY, pieceW, pieceH);
[newPiece setCenter:CGPointMake(pieceX, pieceY)];
[newPiece setTag:[piece tag]];
[[self view] addSubview:newPiece];
[newPiece release];
And note, many of these newPiece's are added programmatically, because the method that this is in is called more than once, so the images have different centers and images and stuff, so would I need an array to hold all of them?
Thanks
NSMutableArray would probably suit your needs.
Check this very detailed post. It's precisely about handling several programatically added UIImageViews and it worked nice for me.
Create multiple views and make the touched view follow the users touch
Best luck.