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.
Related
I have 2 problem and i am totally confuse. please help me
1) I face one problem that i want to assign click listener to image view which is inside of my subview and that subview is with in cell of UITableView.
In my tableview cell there are two image-view i want to give them click listener and also identify them like which image-view is clicked on which row etc etc.
if i write scrollview.userinteractionEnable=YES; than my didSelectRowAtIndexPath Not responds.
i know its because of subview.
But if i change scrollview.userinteractionEnable=NO; than my didselectrowatIndexpath code executes. but scrollview does not scroll to horizontal..
What do i do ? I want horizontal scroll plus Image-view click Listener on both ImageView.
** Solve click problem by crating scrollview sub class**
This is my Customcell class
cellScrollViewClass *scrollView = [[cellScrollViewClass alloc] initWithFrame:CGRectMake(0.0,0.0,430,187)];
scrollView.contentSize = CGSizeMake(scrollView.frame.size.width * 3,scrollView.frame.size.height);
scrollView.scrollEnabled=YES;
scrollView.userInteractionEnabled=YES;
for (int i = 0; i < 3; i++) {
CGRect frame;
frame.origin.x = scrollView.frame.size.width * i;
frame.origin.y = 0;
frame.size = scrollView.frame.size;
if(i==2) // to check Last item must be train Engine
{
UIView *EngineView = [[UIView alloc]initWithFrame:frame];
UIImageView *engineImageView = [[UIImageView alloc]initWithFrame:CGRectMake(-112.5, 6, 430, 180)];
UIImage *Image = [UIImage imageNamed:#"backengine.png"];
engineImageView.contentMode = UIViewContentModeScaleAspectFit;
engineImageView.image = Image;
[EngineView addSubview:engineImageView];
[scrollView addSubview:EngineView]; // add 3rd imageview that is Train Engine to end of scrollview
}
else{ // Not equal to 2 than it must be wagon of train.
UIView *wagon = [[UIView alloc]initWithFrame:frame];
UIColor *background = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:#"wagon.png"]];
wagon.backgroundColor = background;
UIView *videoviewContainer = [[UIView alloc]initWithFrame:CGRectMake(20, 40, 220 , 200)];
UIImageView *videoImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0,0, 220, 100)];
UIImage *bgImage = [UIImage imageNamed:#"video.png"];
videoImageView.image = bgImage;
videoviewContainer.contentMode = UIViewContentModeLeft; // set Video Image view to left hand side of wagon UIView
videoImageView.tag=2;
[videoviewContainer addSubview:videoImageView];
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(singleTapGestureCaptured:)];
[videoImageView addGestureRecognizer:singleTap];
[videoImageView setMultipleTouchEnabled:YES];
[videoImageView setUserInteractionEnabled:YES];
UIView *textUiView = [[UIView alloc]initWithFrame:CGRectMake(238,28, 150 , 187)];
textUiView.contentMode = UIViewContentModeRight;
UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(28,10, 150 , 87)];
label.text=#"This is testing text for IOS app to check line are aligned or not and to check video image and nested views for UIviews";
label.backgroundColor = [UIColor clearColor];
label.textColor=[UIColor redColor];
label.numberOfLines = 4;
[textUiView addSubview:label];
[wagon addSubview:textUiView];
[wagon addSubview:videoviewContainer];
[scrollView addSubview:wagon];
[self.contentView addSubview:scrollView];
}
}
}
return self;
}
- (void)singleTapGestureCaptured:(UITapGestureRecognizer *)gesture
{
NSLog(#"Touch event on view %d",gesture.view.tag);
}
And I created Scrollview subclass like this..
#implementation cellScrollViewClass
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
NSLog(#"You are in scrollview");
}
return self;
}
IS this one is right method of Implementation?
Any Help is Appreciated . Thank you in advance.
Use UITapGestureRecognizer. Create and attach a tap gesture recogniser to each image view when you create it. Also set the tag of the image view when you create it so you can identify which one it is on the cell.
When you get the callback from the recogniser you can get the tag by:
recogniser.view.tag
And you can get the table view cell by looping on the superview until you find a table view cell class:
UIView *superView = recogniser.view.superview;
while (superView != nil && ![superView isKindOfClass:[UITableViewCell class]]) {
superView = superView.superview;
}
Then you can get the index path from the table view using
[tableView indexPathForCell:superView];
To get the on click listener for UIImageView have a category of it & use touches begin method and delegate callback to 'tableViewController'.
Use tags to identify which image is clicked & which row.
To avoid overlap, if the cell us already allocated just remove the previous images to do this have a else condition.
you need to implement the UIScrollView delegate callbacks and check what kind of scroll the user is doing (horizontal scroll or vertical scroll) and then changing the tableview or the scrollview offset manually, thats pretty much the only way i see this...
as for your image you need to set a UIButton for everyImage and link them to a selector, then you can use the tag of the button to know what image it was.
you can add a custom button over the imageview with same frame of image view and the you can add the selector on the button.
For handling gestures on UIImageView make sure that the UIImageView that you are using has the userInteractionEnable = YES by default is set to NO
After a lot of search I am posting this Question, I have to place an image at the bottom of a UITextfield, I have tried it with the following code :
letterField.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
letterField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
letterField.textAlignment = UITextAlignmentCenter;
letterField.borderStyle = UITextBorderStyleNone;
UIImageView *myView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:#"text_line.png"]];
[letterField setLeftView:myView];
[letterField setRightViewMode:UITextFieldViewModeAlways];
[myView release];
// letterField.background = [UIImage imageNamed:#"text_line.png"];
// [letterField setBackground:[UIImage imageNamed:#"text_line.png"]];
letterField.textColor = [UIColor whiteColor];
letterField.returnKeyType = UIReturnKeyDone;
[yourtextfield insertSubview:imgViewTitleBackGround atIndex:0];// mgViewTitleBackGround is image view with background image.
//Or
[yourtextfield setBackground:[UIImage imageNamed:#"text_line.png"]];// you can add your image
yourtextfield.textColor = [UIColor redColor];
Hope, this will help you..enjoy
Sorry, my previous answer was totally wrong. From what I can see your image is text_line.png - i suppose it's some kind of separator line, what can i suggest you to try is create a new UIView with the bounds of the UITextField, then add the text field inside this view and add the UIImage view again as subview of this view centering it properly. I don't know if this will fit your needs, but you can give it a try.
I have a uitableview with 2 cells (custom tableviewcells) and a button for login. I made them programmatically. Now I want to put a background image behind the 2 custom cells and the button. I went into IB and put the image view on top of the tableview and then put a picture on it which I want as the background. Then I went into viewDidLoad and put this bit of code tblSimpleTable.backgroundColor = [UIColor clearColor]; to clear the tableviews background colour.
It now looks like this:
But the background does not appear. Does anyone know how to fix this?
Thanks.
viewDidLoad
- (void)viewDidLoad {
[super viewDidLoad];
self.dataSourceArray = [NSArray arrayWithObjects:
[NSDictionary dictionaryWithObjectsAndKeys:
#"UITextField", kSectionTitleKey,
#"TextFieldController.m: textFieldNormal", kSourceKey,
self.textFieldNormal, kViewKey,
nil],
nil];
UIButton *loginButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
loginButton.frame = CGRectMake(60,140,200,38); // position in the cell and set the size of the button
[loginButton setTitle:#"Login" forState:UIControlStateNormal];
// add targets and actions
[loginButton addTarget:self action:#selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
// add to a view
[self.view addSubview:loginButton];
tblSimpleTable.backgroundColor = [UIColor clearColor];
//tblSimpleTable.backgroundView = nil;
//UIImageView *imageView = [[UIImageView alloc] initWithImage:#"Background-Red.png"];
//imageView.frame = tblSimpleTable.frame;
//tblSimpleTable.backgroundView = imageView;
self.title = NSLocalizedString(#"TextFieldTitle", #"");
// we aren't editing any fields yet, it will be in edit when the user touches an edit field
self.editing = NO;
}
Why don't you use backgroundView property of the UITableView object?
UIImageView * imageView = [[UIImageView alloc] initWithImage:yourBackgroundImage];
imageView.frame = tblSimpleTable.frame;
tblSimpleTable.backgroundView = imageView;
Of course, backgroundView will be resized if you don't set the frame so skipping the second line should also not be a problem.
What you have should probably work out. Still try this :
Add
tblSimpleTable.backgroundView = nil;
in viewDidLoad
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];
It's my first iphone app, and i have trouble with styling my tableView.
I have two images (png), one for standard cell state, and one for selected state.
In my subclassed cell, I tried the following :
1) setting up front the backgroundView and selectedBackgroundView
UIImage *ib = [UIImage imageNamed:#"tab.png"];
UIImageView *back = [[UIImageView alloc] initWithImage:ib];
self.backgroundView = back;
[back release];
UIImage *is = [UIImage imageNamed:#"selected_tab.png"];
UIImageView *selected = [[UIImageView alloc] initWithImage:is];
self.selectedBackgroundView = selected;
[selected release];
The standard cell is fine, but when selected, the two images are shown.
2) just playing with background view on selection :
// storing the 2 uiviews in class attributes
UIImage *ib = [UIImage imageNamed:#"tab.png"];
UIImageView *back = [[UIImageView alloc] initWithImage:ib];
self.storedStandard = back;
[back release];
UIImage *is = [UIImage imageNamed:#"selected_tab.png"];
UIImageView *selected = [[UIImageView alloc] initWithImage:is];
self.storedSelected = selected;
[selected release];
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
if (selected) {
self.backgroundView = self.storedSelected;
}
else {
self.backgroundView = self.storedStandard;
}
}
It nearly works, but the images don't fit the cell, i don't know to stretch them to the size of the cell.
For me, the first solution should have been the one, based on the properties' names, and the second solution seems like a hack (like 90% of the tutorials i seen btw), so i'm a bit frustrated.
To sum up : why the first one doesn't work, and how could i force images to take all the cell space ?
Thanks a lot :)
if you have a UITableViewDelegate, you should be able to just change the backgroundView's image in the willSelectRowAtIndexPath: method and then change it back in the didSelectRowAtIndexPath: method. This is a bit of a hack however.