Please I want change text of any lbl I create it in for loop in click method
such as i want change text of the second lbl.
If any way to access uilabel by tag value.
for(int i=1,i<5,i++){
UILabel *lbl=[[UILabel alloc]initWithframe:GCrectMake(0,0,50,50)];
lbl.tag=i;
lbl.text=#"Quan:0";
[self.view addSubview:lbl];
}
-(void)click:(id)sender{
}
You just call and it will return your label.
UILabel *lbl = (UILabel *)[self.view viewWithTag:(int)];
Related
I create an instance of UITextView programmatically. I want to add some text to particular area in UITextView programmatically. Here is my code to create UITextView.
UITextView *textView =[[UITextView alloc]init];
textView.frame=CGRectMake(0,0,282,210);
[textView setReturnKeyType:UIReturnKeyDone];
[self.view addSubview:textView];
For example I want to add some text to particular Area CGRectMake(260,190,20,20).
Then add this text to UITextView.
Programmatically, please any one guide me, how is it possible to do this?
You could add an UILabel there.
UITextView *textView = [[UITextView alloc] init];
TextView.frame = CGRectMake(0.0,0.0,282.0,210.0);
[textView setReturnKeyType: UIReturnKeyDone];
UILabel *label = [[UILabel alloc] init];
label.frame = CGRectMake(260.0,190.0,20.0,20.0);
label.text = #"T"; //here you set the text you want...
[textView.view addSubview: label];
[self.view addSubview: textView];
I have a problem, how i can show the line between check mark and move at the time of tableview edit. like same as in below image.
explain the process or else if possible please send me to example code.
Thanks in advance.
Look at this :
Declare BOOL checkMark; in .h
check its value.
// This all code in Cell For Row At IndexPath :
for (UIView *ObView in [cell.contentView subviews])
{
[ObView removeFromSuperview];
}
if(checkMark == YES) // you can check here by imdexPath.row.
{
UILabel *lbl = [[UILabel alloc]initWithFrame:CGRectMake(10,5,150,30)];
lbl.text = #"";
[cell.contentView addSubview:lbl];
UIImageView *CheckImage = [[UIImageView alloc]initWithFrame:CGRectMake(160,5,20,20)];
CheckImage.image = [UIImage imageNamed:#""];
[cell.contentView addSubview:CheckImage];
UIImageView *BarImage = [[UIImageView alloc]initWithFrame:CGRectMake(185,5,0.5,30)];
BarImage.image = [UIImage imageNamed:#""];
[cell.contentView addSubview:BarImage];
UIImageView *tblImage = [[UIImageView alloc]initWithFrame:CGRectMake(160,5,20,20)];
tblImage.image = [UIImage imageNamed:#""];
[cell.contentView addSubview:tblImage];
}
else
{
UILabel *lbl = [[UILabel alloc]initWithFrame:CGRectMake(10,5,150,30)];
lbl.text = #"";
[cell.contentView addSubview:lbl];
UIImageView *tblImage = [[UIImageView alloc]initWithFrame:CGRectMake(160,5,20,20)];
tblImage.image = [UIImage imageNamed:#""];
[cell.contentView addSubview:tblImage];
}
Note: frames are temporary.
SO you basically have a tableView and you want to add that image "|" in your tableViewCell when you are editing.
I would assume you already have editingEnabled for your tableView, and you will need to implement
- (void)setEditing:(BOOL)editing animated:(BOOL)animate
{
if (editing) {
// Configure self.tableView and individual cells and add the "|" as a subView.
// It will all be tricky, and you should be able to logically place the vertical bar
// But whatever you want to be in your EDIT mode, you will have to configure it here.
} else {
// Re-configure and implement the 'correct' cells back to normal tableView
}
}
Create a UIView with 1px as width and grey as backgroundColor, and add this to the right of check mark should be fine.
If you Edit option is an image then you can do the code like below to show a line.
Steps
1] First import QuartzCore/QuartzCore.h
2] set border width and border color property of your Edit image.
[editImageView.layer setBorderWidth:2.0];
[editImageView.layer setBorderColor:[[UIColor grayColor] CGColor]];
//If you putting a button for edit then also you can set the same. Just replace the editImageView with your editButton
Hope you get exact you want!:)
Take uiimageview in table cell and set its width to 1. Set height according to your tablename.cell.height.
It will definitely solve your problem
You can customize your tableview cell.Just add the subviews at the time of cell creation and put it hidden untill click on edit button.
I am working on a table under iOS, I added a couple of cells, and each cell has one UITextField added as a subview. An excerpt:
UITextField *t = [[UITextField alloc] initWithFrame:CGRectMake(20.0, 5.0, 220.0, 20.0)];
// here I set properties for t ...
t.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleWidth;
[cell addSubview:t];
cell.autoresizeSubviews = YES;
// if needed, I set the UIImageView for the cell
if (...) {
cell.imageView.image = [UIImage imageNamed:#"myimage.png"];
t.frame = CGRectOffset(text.frame, 33, 0);
}
[t release];
What happens? When I enter the editing mode for the tabel, I'd expect that each cell will resize to make the red minus sign visible, and that the UITextField will move to right to remain aligned to the cell itself, as the other components. But this do not happen.
Also, I tried to change the autoresizingMask param using various combinations of UIViewAutoresizingFlexibleLeftMargin, UIViewAutoresizingFlexibleRightMargin and UIViewAutoresizingFlexibleWidth, but without success.
Am I doing something wrong here? Should I change the way I add the text field as a subview?
Thank you!
add your views to the contentView of the cell:
[cell.contentView addSubview:t];
I want to add uilabels according to mutable array at run time.
actually i have some labels texts in nsmutablearray.and i want to create label at run time and fill the text in label.plz suggest any example or provide guidance
If you have an array of NSStrings and you want to create a UILabel for each text you can do:
for(NSString *text in myArray){
UILabel * label = [[UILabel alloc] initWithFrame:CGRectMake(...)];
[label setText:text];
[aView addSubview:label];
[label removeFromSuperview];
}
In my app that consist of a grouped tableView,the detailTextLabel displays dates entered through a datepicker. and i use this dates to retrieve data from webservice. What i want to do is to add UILabels to detailTextLabel of the cells so that i can access the label's text property to get the dates and send request to webservice. i tried adding label to the detailTextLabel like this
cell.detailTextLabel = self.fromDate //fromDate is an instance of UILabel;
But its showing me error...
How can i fix this
You should set cell.detailTextLabel.text to modify it's contents, and possibly change the layout of cell.detailTextLabel, but not try to assign another UILabel to it.
You might want to add your own label as a subview, then do something along the lines of
UILabel *lbl = [[UILabel alloc] initWithFrame:CGRectMake(160.0f,23.0f,150.0f,20.0f)];
lbl.textAlignment = UITextAlignmentRight;
lbl.font = [UIFont fontWithName:#"Arial" size:14.0f];
lbl.textColor = [UIColor lightGrayColor];
lbl.text = [#"Ref.No. " stringByAppendingString:refno];
[cell addSubview:lbl];