Please give me an advice.
I create UILabels programmatically (dynamic).
Is there is a chance to add Event to them?
What I want by steps:
I create UILabel;
I set Event to it; (NSNotification?)
When I do some action (rotate, for example) I want that Label is changed or removed. An extended example: I create Labels and when I rotate device I want that part of them (which with attached Events) disappear in animation.
I create a lot of Labels, so I can't just set them global variables. And I can't set them tags unlimited. So UILabel *label = (UILabel*)[self.view viewWithTag:labelCount not a solution. Getting element by 'viewWithTag' has one more trouble - when set animation to that element and that element already in animation happens collision - they plays one over other...
I create Labels like this:
CGRect *labelFrame = CGRectMake(left, top, width, height);
UILabel *label = [[UILabel alloc] initWithFrame:labelFrame];
label.text = #"Hi, I'm one of these army of labels";
[self.view addSubview:label];
PS: Sorry for English.
I assume you have a UIViewController that has a bunch of labels. I would recommend an IBOutletConnection for storing a reference to all of your labels (assuming storyboard).
//You will need to connect all of these labels through Interface Builder.
#property (nonatomic, strong) IBOutletCollection(UILabel) NSArray *labels;
In one of the following rotation methods (Detect rotation changes in iOS) do your rearranging.
//Called whenever orientation changes
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
for (UILabel *label in self.labels) {
//Make each label disappear here.
}
}
Related
how to set value for uilabel using objective-c without any connection from storyboard to source-file.
In a storyboard, suppose a label is dropped into uiview and we don't want to bound connection to .h file , so how is it possible to set value using objective-c.
You can create UILabel Programatically like,
UILabel *myLabel = [[UILabel alloc]initWithFrame:CGRectMake(91, 15, 0, 0)];
myLabel.text = #"hello";
[self.view addSybview:myLabel];
Second thing you can set tag from storyboard and by this tag you can access label.
Third thing you can get NSArray of subviews of self.view means your main view and from that array you can access that label.
these are the possible ways. :)
hope this will help :)
You can assign a tag value to your UILabel from the storyboard, then you can use that value to access the view from your code:
UILabel *label = (UILabel *)[self viewWithTag:1];
[label setText:#"setting some value"];
I am creating a tableView with custom cells, with each cell being created with the following code:
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:kEditSymbolCellId];
I have returntableView.isEditing; set.
and i have the minus button visible from the get go. With the editing style set toUITableViewCellEditingStyleDelete
somewhere
(if (editingStyle == UITableViewCellEditingStyleDelete) { passes).
Where would i have to change the code to add the accessibility label.
I am creating the cell of a custom class- the .h has only this in it:
#interface WidgetEditCell : UITableViewCell
#property (retain, nonatomic) IBOutlet UILabel *symbolLabel;
#property (retain, nonatomic) IBOutlet UILabel *subtitleLabel;
With ainitWithStyle and asetSelected in the .m
nothing that changes the cursed minus image.
someone please help.
By default, there should be an accessibilityLabel built in that reads your label and places the message "delete" in front. I have tested a custom cell, see below:
If that does not suit your needs, I have these suggestions:
Add a UIAlertView to display a message when a person wishes to delete. This can have a voice message enabled, and, realistically is a pleasant way of going about business providing things aren't being deleted (my opinion).
Create your own custom delete function following this tutorial from Ray Wenderlich. I have used it and find it really practical for customisability.
I have not tried this, but create your accessibilityLabel whenever the edit option is used by creating a custom button, or UILabel that is set to Transparent.
UIButton *someButton = [[UIButton alloc] initWithFrame:CGRectMake(x, y, h, w)];
someButton.backgroundColor = [UIColor clearColor];
someButton.accessibilityLabel = #"SomeNSString";
Have it fill the area around the button perhaps and then have it perform the delete function if that's called so it appears seem less. It's probably not the greatest option on the planet but I have yet to see another way.
Image from Ray Wenderlich
I want to add a UILabel as a subview to a UITextField. It should to be positioned at the exact same coordinates as the normal text contents. (I am aware of UITextField.placeholder, but it does not fit my requirements.)
I have created a class that inherits from UITextField and assigned it to a text field in a storyboard. I have added the following in the initWithCoder method:
placeholderLabel = [[UILabel alloc] init];
// set font, color, text
[placeholderLabel sizeToFit];
// This rect is useless to me :(
CGRect frame = [self textRectForBounds:placeholderLabel.bounds];
[self addSubview:placeholderLabel];
I could use the initWithFrame method, instead of init, or set the UILabel's frame property but then I would need to know a GCRect. Do I really need to calculate it by hand based on the UITextField's height, paddings, font size, and possible left view etc?
I need help on populating my uilabels. I have three uiviews and each have five labels. I need to change the labels data when the view changes, i am using uisegmentedbutton to change views..What would be the best approach? Thanks.
You do it in exactly the same way you got a reference to the views, e.g. viewPanel1. You need a property or instance variable for each one. Let's say it's a property. If the labels were created in the nib, you must make an outlet for that property. If the labels were created in code, you must assign each one to a property as you create it. Now you can use that property, which persists, to refer to the label it points to.
Let's say I have
#property (nonatomic, weak) UILabel* label1
Then later I can create the label and put it in the interface:
UILabel* lab = ...
self.label1 = lab;
[someView addSubview:lab];
Then even later I can refer to the label:
self.label1.text = #"Bart Simpson Was Here";
Let's do it with an array of labels. We have:
#property (nonatomic, strong) NSMutableArray* labels1;
Then later I must actually make the array:
self.labels1 = [NSMutableArray new];
Then still later I can create the label and put it in the interface, and add it to the array:
UILabel* lab = ...
[self.labels1 addObject:lab];
[someView addSubview:lab];
Then even later I can refer to the label:
self.labels1[0].text = #"Bart Simpson Was Here";
(because this is the first label added to labels1)
I have a scroll view in which i have a label. i have to update the label's text each time the user scrolls the scrollview. i want to update the label's value with pageindex.I am getting the page index in scrollviewdelegate method but unable to update it in label as the label gets loaded in viewDidload. Any way to refresh or update the label's text from scrollview delegate method?
HERE pageNumber is number which update and get when you scroll UIScrollView
Write this code in where your get pageNumber
Yourlbl.text = pageNumber;
Make the label a property and use the property to set the labels text.
Property (assuming arc enabled project):
#property (nonatomic, strong) UILabel *myLabel;
ViewDidLoad:
- (void)viewDidLoad {
self.myLabel = [UILabel new];
}
and update your label texts from inside the viewController like this:
self.myLabel.text = #"test";
take all the values in one array and assign the label text based on the pageindex like below
label.text=[titlesArray objectAtIndex: pageindex];
for achieving this one you can take label globally.
EDIT:-
for achieving this one you can do two ways.
1.take UILabel in Xib and connect the label with some name and you can set the labelname.text in scrollviewDidEnd method .
2.take uilabel programatically and define that one in .h file and change the textscrollviewDidEnd particular method.