how do i get the name of a component in IOS? - ios

I just dragged a UIImageview onto a storyboard in xcode 5. I am coming from .NET where this would add an object of type UIImageView to the main form. Is this the way to think about it in IOS? Where do I click in the xcode IDE to get the name of the instance of UIImageView?

You dragged a UIImageView into a storyboard. You need to see which view controller this UIImageView object lives in and then you can connect that UIImageView to an IBOutlet, which is how your view controller (the implementation or code for which you're working on, which also happens to be a subclass of UIViewController) will interact with the UIImageView object.

You have to write a IBOutlet in the corresponding ViewController.h file like this.
#property (nonatomic , strong) IBOutlet UIImageView *myImageView ;
Then in your ViewController.m , use #synthesize after #implementation tag.
Then go back to the Interface Builder and connect the IBOutlet myImageView to your ImageView which you have dragged there. Hope it helps.

Related

How to resize background image as needed

i'm trying to create an ui button with image and text.
What i need is simple:
an image centered on the first row and on another row a label centered.
So i've created an uibutton in my storyboard, set text and background in this way:
But the result isn't good for me.
This is what i have:
and this is what i need:
Can someone help me?
thanks!
EDIT
I've created a custom UIButton in this way:
.h
#import <UIKit/UIKit.h>
#interface MenuButton : UIButton
#property (weak, nonatomic) IBOutlet UIImageView *image;
#property (weak, nonatomic) IBOutlet UILabel *text;
#end
.m
#import "MenuButton.h"
#implementation MenuButton
#end
And in interface builder i create a view with class MenuButton addedd an image and a label and connecting to .h.
Now my question is:
How can i pass to that new button the image and the label in order to instantiate multiple "custom button" with different value inside?
Thanks!
You just create a UIButton subclass.
1)
If you are using IB: then you can create 2 properties in the .h
#property (weak, nonatomic) IBOutlet UIImageView *image;
#property (weak, nonatomic) IBOutlet UILabel *text
next you need to connect all the properties to the objects in the IB
If you are using code the remove the IBOutlet and move the properties to the .m
2)
Now all you need to do is manage the behaviour of the properties.
in IB, just add the autolayout constraints to the subclass and change their constant property value - check this tutorial
in code, you can do this by setting their frame with animation to make them larger/smaller
EDIT
Ok, after reading your update you need to change the subclass from UIButton to UIView.
This way you can add a UIView in your storyboard and add the UImageView & UILable. After doing so you can change the UIView's class to your subclass.
Then, click on the UIView and open the connections inspector. You will see the IBOutlets you have declared in th UIView subclass, you can just drag from the connections inspector to the UIImageView & UILabel to crete the connections

how to get image name when click on uiimageview?

I have a UIScrollview.
In the UIScrollview there are 4 UIImageViews with images.
When I click on any UIImageview I want to know the name of that image.
UIImageView just keeps the pointer to the place the UIImage is stored inside the memory, so it's not possible with UIImageView. You would need to create a subclass of UIImageView with a NSString variable which stores the value to access it later. Something like this:
#import <UIKit/UIKit.h>
#interface MyImageView : UIImageView
#property (strong, nonatomic) NSString *imageName;
#end
The image names are not stored in UIImage objects so you have to keep them somewhere else for lookup. To detect touches in image views you either have to subclass them and add code for touch detection, add tap recognizers or replace them with buttons.

Reference to a Table in a ViewController

I want to change that separator line color, that one that separate the lines, in my UITableView. I have this code in my views.
self.tableview.separatorColor = [UIColor colorWithRed:115/255.0 green:83/255.0 blue:14/255.0 alpha:1];
I don't have any problems in my UITableViewControllers, but in my ViewController that has a TableView component I can't do this away.
Help please.
You need to have reference to your UITableView. You can achieve this by adding
#property (nonatomic, weak) IBOutlet UITableView *tableView;
To your .h class file and then add New Referencing Outlet in your Interface Builder.
If you don't know how to create referencing outlet take a look at this post:
xcode5 add new referencing outlet

programatically Changing uiwebview frame which was created using nib

I have a UIwebview created using nib. I have many controllers accessing this webview(in nib) . For each call from different controllers the size of webview in nib should be changed accordingly.How to implement this programatically?
Thanks in advance
You need only create outlet of this UIWebView in your controller.(and property)
IBOutlet UIWebview *webExample;
#property (nonatomic, strong) IBOutlet UIWebview *webExample;
When in your code send a call to the UIViewWeb you can detect de sender and change the view's frame size.
webExample.layer.frame=CGRectMake(x,y,200,200);

Change UIImageView Image path

I'm completely new to objective-c and iOS programming with it. I am displaying a UIImageView with a default image path I set via storyboard. Now, I am trying to change the image to a different image, by changing the path to a different one.
I think I have set everything up so that I can programmatically manipulate the class (IBOutlet, #property, allocing, etc), but perhaps I am doing something wrong there. Otherwise, I am changing the image path via:
IMG.image = [UIImage imageNamed:#"s.png"];
Is this correct? If so, here is the other piece of relevant code in my .m file:
- (void)viewDidLoad
{
_IMG = [[UIImageView alloc] init];
}
In the #interface part of my .h file:
IBOutlet UIImageView *IMG;
And then the rest of my .h file:
#property (strong, nonatomic) IBOutlet UIImageView *IMG;
Does anyone see anything incorrect? Thanks, I am a complete beginner so I apologize if this is an extremely basic thing.
Firstly, get rid of this line from your .h (you don't need it as you are declaring a property):
IBOutlet UIImageView *IMG;
Next, check that you have wired up your IBOutlet property to the UIImageView in Interface Builder (hold down CTRL and click on your UIImageView). Make sure there is an entry under Referencing Outlets. If not you will need to CTRL-drag to create one.
Hope this helps.
If you are using storyboard you dont need to alloc init your view, remove that code.

Resources