Hello everyone I'm trying to embed images for each textfield ...
When I go to insert the text into the first textfield, the image also has an impact on the second textfield. I would that images visualizzassero each textfield that the user selects and not directly to all ... Where am I doing wrong?
Thanks to all
-(BOOL)textFieldShouldEndEditing:(UITextField *)textField {
NSString *nomecognome = self.FF_NomeCognomeTexfield.text ;
NSString *user = self.FF_UsernameTextField.text ;
if ([nomecognome length] == 0 || [user length] == 0 ){
FF_NomeCognomeTexfield.leftViewMode = UITextFieldViewModeAlways;
UIImageView* imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 32, 32)];
imageView.image = [UIImage imageNamed:#"FF_CheckOFF"];
imageView.contentMode = UIViewContentModeScaleAspectFit;
FF_NomeCognomeTexfield.leftView = imageView;
FF_UsernameTextField.leftViewMode = UITextFieldViewModeAlways;
UIImageView* imageView1 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 32, 32)];
imageView1.image = [UIImage imageNamed:#"FF_CheckOFF"];
imageView1.contentMode = UIViewContentModeScaleAspectFit;
FF_UsernameTextField.leftView = imageView1;
} else {
FF_NomeCognomeTexfield.leftViewMode = UITextFieldViewModeAlways;
UIImageView* imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 32, 32)];
imageView.image = [UIImage imageNamed:#"FF_CheckON"];
imageView.contentMode = UIViewContentModeScaleAspectFit;
FF_NomeCognomeTexfield.leftView = imageView;
FF_UsernameTextField.leftViewMode = UITextFieldViewModeAlways;
UIImageView* imageView1 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 32, 32)];
imageView1.image = [UIImage imageNamed:#"FF_CheckON"];
imageView1.contentMode = UIViewContentModeScaleAspectFit;
FF_UsernameTextField.leftView = imageView1;
}
return YES;
}
All textFields trigger this method. You should use the argument 'textField' in an if-statement to determine the identity of the sender.
if( [textField isEqual: FF_NomeCognomeTexfield] == YES){
...
}
Related
I currently have a scroll view loading images from an array, here's my code:
icons = [[NSMutableArray alloc]initWithObjects:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:#"one" ofType:#"png"]], [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:#"two" ofType:#"png"]], [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:#"three" ofType:#"png"]],nil];
int numberOfItems = [icons count];
NSLog(#"Number of objects: %i",numberOfItems);
for (int i = 0; i < numberOfItems; i++) {
if (i <= 3) {
finalFrame = CGRectMake( i*(80), 12, 80, 80);
}
UIButton *iconButton = [UIButton buttonWithType:UIButtonTypeCustom];
iconButton = [UIButton buttonWithType:UIButtonTypeCustom];
iconButton.frame = CGRectMake(0, 0, 57, 57);
iconButton.center = CGPointMake(40, 29);
iconButton.imageView.contentMode = UIViewContentModeScaleToFill;
[iconButton addTarget:self action:#selector(selected:) forControlEvents:UIControlEventTouchUpInside];
iconButton.tag = i;
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
dispatch_async(queue, ^{
UIImage *icon = [icons objectAtIndex:i];
dispatch_sync(dispatch_get_main_queue(), ^{
[iconButton setImage:icon forState:UIControlStateNormal];
});
});
[sub addSubview:iconButton];
sub = [[UIView alloc] initWithFrame:finalFrame];
[scrollView addSubview:sub];
}
The NSLog reads 3 objects, but my scroll view is only showing 2 of them, what am I doing wrong?
I think in it is in for loop for it should be like this
(int i = 0; i <= numberOfItems; i++)
hi iam trying to put a uisegmented controls over a uiscrollview beacuse i want them to scroll horizontally this is the code i tried
UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 600, 300)];
scroll.contentSize = CGSizeMake(500, 50);
scroll.showsHorizontalScrollIndicator = YES;
scroll.pagingEnabled = YES;
scroll.showsHorizontalScrollIndicator = YES;
scroll.autoresizingMask = YES;
scroll.autoresizesSubviews = YES;
NSArray *itemArray = [NSArray arrayWithObjects: #"One", #"Two", #"Three",#"four",#"Five", nil];
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:itemArray];
segmentedControl.frame = CGRectMake(0,10, 500, 50);
segmentedControl.segmentedControlStyle = UISegmentedControlStylePlain;
segmentedControl.selectedSegmentIndex = 4;
[scroll addSubview:segmentedControl];
[self.view addSubview:scroll];
any one please help me to accomplish this . thanks in advance happy coding
The frame for the scroll View must be less than the Content size of scroll view. If you will increase your content size definitely it will work. For example:-
UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 50)];
scroll.contentSize = CGSizeMake(500, 50);
scroll.showsHorizontalScrollIndicator = YES;
scroll.pagingEnabled = YES;
scroll.showsHorizontalScrollIndicator = YES;
scroll.autoresizingMask = YES;
scroll.autoresizesSubviews = YES;
NSArray *itemArray = [NSArray arrayWithObjects: #"One", #"Two", #"Three",#"four",#"Five", nil];
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:itemArray];
segmentedControl.frame = CGRectMake(0,10, 500, 50);
segmentedControl.segmentedControlStyle = UISegmentedControlStylePlain;
segmentedControl.selectedSegmentIndex = 4;
[scroll addSubview:segmentedControl];
[self.view addSubview:scroll];
If its supportive please mark the answer correct. Thanks very much.
I have a UITable that can collapse on header section click.
I need the header sections to have unique text in them.
I can use cell.textlabel.text = #""; and this works fine, however I want to add more labels to the cell and position these i.e
lbl123 = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 290, 20)];
lbl123.font = [UIFont fontWithName:#"Trebuchet MS" size:12.0f];
lbl123.textColor = [UIColor blackColor];
lbl123.backgroundColor = [UIColor clearColor];
lbl123.highlightedTextColor = [UIColor whiteColor];
lbl123.opaque = NO;
lbl123.adjustsFontSizeToFitWidth = TRUE;
lbl123.numberOfLines = 0;
lbl123.lineBreakMode = UILineBreakModeWordWrap;
[cell addSubview:lbl123];
lbl123.text = #"test";
but when I add this to the section on "cellforindexpath" It replicates itself on cells further down the table.
any ideas why this is happening??
full code below:-
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *cellValue = 0;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"MyIdentifier"];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:#"MyIdentifier"];
}
if (tableView.tag == 2)
{
UILabel *lbl123;
if ([self tableView:tableView canCollapseSection:indexPath.section])
{
cell.textLabel.font = [UIFont fontWithName:#"Trebuchet MS" size:12.0f];
if (!indexPath.row)
{
cell.textLabel.backgroundColor = [UIColor clearColor];
UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 60)];
[bgView setBackgroundColor:[UIColor blackColor]];
[bgView setAlpha:0.3];
[cell setBackgroundView:bgView];
lbl123 = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 290, 20)];
lbl123.font = [UIFont fontWithName:#"Trebuchet MS" size:12.0f];
lbl123.textColor = [UIColor blackColor];
lbl123.backgroundColor = [UIColor clearColor];
lbl123.highlightedTextColor = [UIColor whiteColor];
lbl123.opaque = NO;
lbl123.adjustsFontSizeToFitWidth = TRUE;
lbl123.numberOfLines = 0;
lbl123.lineBreakMode = UILineBreakModeWordWrap;
[cell addSubview:lbl123];
lbl123.text = #"";
if(indexPath.section == 1)
{
cell.textLabel.font = [UIFont fontWithName:#"Trebuchet MS-Bold" size:15.0f];
cell.textLabel.text = [NSString stringWithFormat:#"My Results Overview:"];
cell.textLabel.textColor = [UIColor whiteColor];
cell.textLabel.numberOfLines = 3;
cell.textLabel.opaque = YES;
UIImageView *av = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 294, 80)];
av.backgroundColor = [UIColor clearColor];
av.opaque = NO;
av.image = [UIImage imageNamed:#"Blue bar 720x115.png"];
cell.backgroundView = av;
}
if(indexPath.section == 2)
{
cell.textLabel.font = [UIFont fontWithName:#"Trebuchet MS-Bold" size:15.0f];
cell.textLabel.text = [NSString stringWithFormat:#"Result1:"];
cell.textLabel.textColor = [UIColor blackColor];
cell.textLabel.numberOfLines = 3;
cell.textLabel.opaque = YES;
UIImageView *av = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 294, 120)];
av.backgroundColor = [UIColor clearColor];
av.opaque = NO;
if ([confidenceCOL isEqualToString:#"Red"])
{
av.image = [UIImage imageNamed:#"redPanel.png"];
}
if ([confidenceCOL isEqualToString:#"Green"])
{
av.image = [UIImage imageNamed:#"greenPanel.png"];
}
if ([confidenceCOL isEqualToString:#"Purple"])
{
av.image = [UIImage imageNamed:#"purplePanel.png"];
}
cell.backgroundView = av;
lbl123.text = #"Test";
}
if(indexPath.section == 3)
{
cell.textLabel.font = [UIFont fontWithName:#"Trebuchet MS-Bold" size:15.0f];
cell.textLabel.text = [NSString stringWithFormat:#"Result2:"];
cell.textLabel.textColor = [UIColor blackColor];
cell.textLabel.numberOfLines = 3;
cell.textLabel.opaque = YES;
UIImageView *av = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 294, 120)];
av.backgroundColor = [UIColor clearColor];
av.opaque = NO;
if ([ambitionCOL isEqualToString:#"Red"])
{
av.image = [UIImage imageNamed:#"redPanel.png"];
}
if ([ambitionCOL isEqualToString:#"Green"])
{
av.image = [UIImage imageNamed:#"greenPanel.png"];
}
if ([ambitionCOL isEqualToString:#"Purple"])
{
av.image = [UIImage imageNamed:#"purplePanel.png"];
}
cell.backgroundView = av;
lbl123.text = #"TestING!";
}
if ([expandedSections containsIndex:indexPath.section]){}
else{}
}
else
{
if(indexPath.section == 2)
{
cellValue = Result1Moretext;
}
if(indexPath.section == 3)
{
cellValue = Result2Moretext;
}
static NSUInteger const k1 = 1;
// Declare references to the subviews which will display the data.
UILabel *lbl1 = nil;
static NSString *kCellID = #"CellID";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:nil];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kCellID];
lbl1 = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 290, 300)];
lbl1.font = [UIFont fontWithName:#"Trebuchet MS" size:12.0f];
lbl1.tag = k1;
lbl1.textColor = [UIColor blackColor];
lbl1.backgroundColor = [UIColor clearColor];
lbl1.highlightedTextColor = [UIColor whiteColor];
lbl1.opaque = NO;
lbl1.adjustsFontSizeToFitWidth = TRUE;
lbl1.numberOfLines = 0;
lbl1.lineBreakMode = UILineBreakModeWordWrap;
[cell.contentView addSubview:lbl1];
}else {
lbl1 = (UILabel *)[cell.contentView viewWithTag:k1];
}
cell.accessoryView.tag = indexPath.row;
lbl1.text = [NSString stringWithFormat:#"%#", cellValue];
return cell;
}
}
else
{
}
}
Thanks
Don't forget that cells are reused in UITableViews to keep memory usage low. So what's happening is you are making a cell, and adding the label to it, then after that cell scrolls of the screen it goes into a reuse pool, gets re-added as a new cell further down and still has the label in it.
What you should do is create all labels etc only when you make a new cell (in the cell==nil section, that's where a cell was not dequeued), and set all the labels in the rest of the code.
You can use view tags to find the label views again later.
eg.
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"MyIdentifier"];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:#"MyIdentifier"];
lbl123 = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 290, 20)];
lbl123.font = [UIFont fontWithName:#"Trebuchet MS" size:12.0f];
lbl123.textColor = [UIColor blackColor];
lbl123.backgroundColor = [UIColor clearColor];
lbl123.highlightedTextColor = [UIColor whiteColor];
lbl123.opaque = NO;
lbl123.adjustsFontSizeToFitWidth = TRUE;
lbl123.numberOfLines = 0;
lbl123.lineBreakMode = UILineBreakModeWordWrap;
[cell addSubview:lbl123];
lbl123.text = #"";
lbl123.tag=123;
} else {
lbl123 = (UILabel *)[cell viewWithTag:123];
}
if(indexPath.section == 2)
{
lbl123.text = #"Test";
}
I want four ScrollViews like iCarousel's CoverFlow in View programmatically. My Code is
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
[super viewDidLoad];
//set up data
wrap = YES;
self.items = [NSMutableArray array];
for (int i = 0; i < NUMBER_OF_ITEMS; i++)
{
[items addObject:[NSNumber numberWithInt:i]];
}
carousel1 = [[carousel1 alloc] init];
carousel2 = [[carousel2 alloc] init];
carousel3 = [[carousel3 alloc] init];
carousel4 = [[carousel4 alloc] init];
carousel1.frame = CGRectMake(0, 0, 320, 120);
carousel2.frame = CGRectMake(0, 120, 320, 120);
carousel3.frame = CGRectMake(0, 240, 320, 120);
carousel4.frame = CGRectMake(0, 360, 320, 120);
carousel1.delegate = self;
carousel2.delegate = self;
carousel3.delegate = self;
carousel4.delegate = self;
carousel1.dataSource = self;
carousel2.dataSource = self;
carousel3.dataSource = self;
carousel4.dataSource = self;
[self.view addSubview:carousel1];
[self.view addSubview:carousel2];
[self.view addSubview:carousel3];
[self.view addSubview:carousel4];
//configure carousel
carousel1.type = iCarouselTypeCoverFlow2;
carousel2.type = iCarouselTypeCoverFlow2;
carousel3.type = iCarouselTypeCoverFlow2;
carousel4.type = iCarouselTypeCoverFlow2;
}
but fail with four warnings with out placing the carousels view on the View. Please help me to overcome this problem. Thanks in advance.
Shouldn't you be initialising them with [[iCarousel alloc] init] instead of [[carousel1 alloc] init]?
Is there any way to set the view page modal during network connecting? I mean all controllers in page do not response the user operation if the network is connecting?
I updated code like:
- (void)loadView
{
[super loadView];
_hudView = [[UIView alloc] initWithFrame:CGRectMake(75, 155, 170, 170)];
_hudView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
_hudView.clipsToBounds = YES;
_hudView.layer.cornerRadius = 10.0;
_activityIndicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
_activityIndicatorView.frame = CGRectMake(65, 40, _activityIndicatorView.bounds.size.width, _activityIndicatorView.bounds.size.height);
[_hudView addSubview:_activityIndicatorView];
[_activityIndicatorView startAnimating];
_captionLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 115, 130, 22)];
_captionLabel.backgroundColor = [UIColor clearColor];
_captionLabel.textColor = [UIColor whiteColor];
_captionLabel.adjustsFontSizeToFitWidth = YES;
_captionLabel.textAlignment = UITextAlignmentCenter;
_captionLabel.text = #"Loading...";
[_hudView addSubview:_captionLabel];
NSArray *buttonNames = [NSArray arrayWithObjects:#"hehe",#"xixi",nil];
UISegmentedControl *segmentControl = [[UISegmentedControl alloc] initWithItems:buttonNames];
segmentControl.frame = CGRectMake(0, 0, TTApplicationFrame().size.width/2, TT_ROW_HEIGHT-10);
segmentControl.segmentedControlStyle = UISegmentedControlStyleBar;
segmentControl.momentary = NO;
segmentControl.tintColor = [UIColor darkGrayColor];
segmentControl.selectedSegmentIndex = 0;
[segmentControl addTarget:self action:#selector(switchPage:) forControlEvents:UIControlEventValueChanged];
self.navigationItem.titleView = segmentControl;
TT_RELEASE_SAFELY(segmentControl);
self.view = [[[UIView alloc] initWithFrame:TTApplicationFrame()] autorelease];
self.tableView = [[[UITableView alloc] initWithFrame:TTApplicationFrame() style:UITableViewStylePlain] autorelease];
self.tableView.rowHeight = 80.f;
self.tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
[self.view addSubview:self.tableView];
[self reload];
[self updateView];
}
and show it like:
- (void)showLoading:(BOOL)show {
if (show) {
self.loadingView = _hudView;
}
else {
self.loadingView = nil;
}
}
As I said in comment, it still cannot cover the buttons of UISegmentedControl, user still can click those buttons...
Instead of using a modalViewController, create a HUD (one of the nice views with a UIActivityIndicators you'll see in the TTCatalogue app) that will block the view and inform the user something is happening while you're making a request.
Just insert them by a [self.view addSubview:theHUDview];.
It's not necessarily good design though, instead, make your network calls asynchronously, in the background.