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
Related
I want to ask, who the Views in the Storyboard, which are attached to a UIViewController are accessable. Who to add them to the UIViewContoller to its views programmaticliy with Objective C. The appear in the Storyboard like this:
and are in the tree in the same hirgachy as the UIViewController Node.
You can take outlet of that view in respective view controller class as you you take outlet of view put in viewcontroller's default view.
Then in your viewDidload you can add that view to your default view!
For example your outlet is outterView then in viewDidload,
[self.view addSubview:self.outerView];
Second thing if you are adding view in viewDidload and you need your view's size as screen size than in viewDidappear you can do like,
self.outerView.frame = self.view.frame;
Ok it was my fault, sorry folks.
I also need an IBOutlet to the to the ViewControllers view. So connect the them in InterfaceBuilder first and give the View the the customClass.
Referencing Outlets
view->UIViewContoller
HelloUIClass *viewThis = [[HelloUIClass alloc] init];
[self.view addSubview:viewThis]
…this is a start not sure about that.
You just have to do it right in Interface Builder!
DRAG AND DROP! the Reference Outlet in to your Headerfile under the #interface.
Open both windows. The Storyboard and your Controller Class .h file.
Grap an REFERENCING OUTLET from the View in File Inspector or right Mouse click and draw line into your Sourcecode. If you have done your class properly it will hook under your #interface line. AfterDroping you have give it a name "myViewInIB" and than you have just something like this:
#interface UIMainView : UIViewController;
#property (weak, nonatomic) IBOutlet UICoustomView *myViewInIB;
than you can use it normaly in your Class (Obj C)
[self.view addSubview:self.myViewInIB]
you said you have class of that view so you can do like this
Suppose your class name is View then,
1) in storyboard give name "View1" of class to view
2) you need to create Class if you want to give size programatically
3) for view size you can also use constraints instead of frame.
View1 *objView = [[View1 alloc]initWithFrame:CGRectMake(100, 100, 200, 200)];
viewObj.center = self.view.center;
viewObj.backgroundColor = [UIColor redColor];//so you can find view easily
[self.view addSubview: objView];
I am learning Swift by creating a small quiz app. I need to create a button with few labels (as shown) for the level. Please guide on how to create such type of button.
The Level number and progress value is dynamic i.e. will be provided programmatically. Is there a way by which I can create a custom button assign it to a class with outlets for labels, so that I can create an object of the class and assign the values of the label and the entire class behaving as a button i.e. when clicked will move to another view controller showing the questions of that level.
You basically answered your own question.
Create a subclass of UIView like so (showing only header file):
#interface MyButton : UIView
#property (nonatomic, weak) IBOutlet UILabel *levelLabel;
#property (nonatomic, weak) IBOutlet UILabel *progressLabel;
#end
Now create a layout file (.xib) with one uiview and uilabels as its children. Set the uiviews class to MyButton and hook up the outlets to the two labels. Remember to set the userInteractionEnabled property of the view to YES.
Use your custom class anywhere in your app by importing "MyButton.h".
EDIT:
In Swift:
class MyButton: UIView {
#IBOutlet weak var lebelLabel: UILabel?
#IBOutlet weak var progressLabel: UILabel?
...
}
Regarding comment:
I created the xib along with labels and their outlets. Can you please tell how to use and initialise MyButton anywhere.
This has been answered on SO countless times before. For one way of doing it, read here
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
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.
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.