I have a toolbar called Ntoolbar. It contain some UILabel, and have a method "insertTitle:(NSString) *title":
- (void) insertTitle:(NSString *)title{
UILabel *newlabel = [ [UILabel alloc ] initWithFrame:CGRectMake((self.bounds.size.width / 2), 0.0, 150.0, 43.0) ];
newlabel.textAlignment = UITextAlignmentCenter;
newlabel.textColor = [UIColor whiteColor];
newlabel.backgroundColor = [UIColor darkGrayColor];
newlabel.font = [UIFont fontWithName:#"Arial Rounded MT Bold" size:(14.0)];
[_ribbon_title addSubview:newlabel];
newlabel.text = [NSString stringWithFormat: #"%#", title];
}
In ViewController, I have an outlet:
#property (strong, nonatomic) IBOutlet NToolBar *nToolBar;
And in ViewDidLoad(), I call this method to add an UILabel
- (void)viewDidLoad
{
[super viewDidLoad];
[_nToolBar insertTitle:#"edit"];
}
Images:
Before adding new label: http://nt9.upanh.com/b2.s32.d2/9a3ff99d74de684dcc2075e98274a6e0_52281369.screenshot20130103at4.png
After adding new label, the old UILabel is covered by new UILabel?
http://nt5.upanh.com/b1.s33.d1/e6dd9ef7e8748dc445d71a5cc28a0d3c_52281635.screenshot20130103at4.png.
How can I add contrains between them?
Related
#interface TopBarController : UIViewController <AVAudioPlayerDelegate, UIAlertViewDelegate> {
UILabel *coinWatch; }
#property (nonatomic,retain) UILabel *coinWatch;
- (UIView *)coinsLabel {
UIView *coinsLabelView=[[UIView alloc]initWithFrame:CGRectMake(36, 17, 100, 15)];
//if (coinsLabelView == nil) {
coinWatch = [[UILabel alloc]initWithFrame:CGRectMake(3, 0, 100, 15)];
coinWatch.font = [self coinsFont];
coinWatch.textColor = [UIColor colorWithRed:1.0 green:0.83 blue:0.16 alpha:1];
coinWatch.text = [NSString stringWithFormat:#"%d", data.getCoins];
NSLog(#"label %d",data.getCoins);
coinWatch.backgroundColor = [UIColor clearColor];
//}
[coinsLabelView addSubview:coinWatch];
return coinsLabelView;
}
- (void) setCoin {
[coinWatch performSelectorOnMainThread:#selector(setText:) withObject:[NSString stringWithFormat:#"%d", data.getCoins] waitUntilDone:NO];
NSLog(#"coin %d",data.getCoins);
NSLog(#"Really updating");
}
I'm new to xcode but this is my simple code for updating coinWatch(UILabel). the label initially has 0 but when I added the coin using other functions(not shown in here), the NSLog prints the correct amount but does not update...When ever I call for setCoin, it does not update the coinWatch text in the view. Please help this miserable newbie!!!
Any idea how to move the UITableViewCell text over so that it doesn't overlap the small image on the left hand side?
here's a screenshot:
thanks for any help
here's my TableCell code:
- (UITableViewCell *)tableView:(UITableView *)tableView1 cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UILabel* nameLb;
UILabel* detailsLb;
UITableViewCell *cell = [tableView1 dequeueReusableCellWithIdentifier:#"log-cell"];
if (cell == nil){
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:#"log-cell"] autorelease];
UIImage* img = [ImgUtil image:[NSString stringWithFormat:#"butList3_%d.png", [[SelectCategory instance] select] + 1 ]];
UIImageView* bgImage = [[[UIImageView alloc] initWithImage:img ]autorelease];
[cell addSubview:bgImage ];
[cell sendSubviewToBack:bgImage ];
nameLb = [[[UILabel alloc] initWithFrame:CGRectMake(5, 5, 250, 40)] autorelease];
[nameLb setNumberOfLines:4];
[nameLb setBackgroundColor:[UIColor clearColor]];
[nameLb setTextColor:[UIColor whiteColor]];
[nameLb setTag:NAME_TEXT];
[nameLb setFont:[UIFont fontWithName:#"Helvetica-Bold" size:15]];
[nameLb setMinimumFontSize:10];
[cell addSubview:nameLb];
//add UIImage
cell.imageView.image = [UIImage imageNamed:#"shop.png"];
detailsLb = [[[UILabel alloc] initWithFrame:CGRectMake(5, 45, 250, 20)] autorelease];
[detailsLb setBackgroundColor:[UIColor clearColor]];
[detailsLb setTextColor:[UIColor whiteColor]];
[detailsLb setTag:DETAILS_TEXT];
[detailsLb setFont:[UIFont fontWithName:#"Helvetica" size:12]];
[cell addSubview:detailsLb];
}else {
nameLb = (UILabel*)[cell viewWithTag:NAME_TEXT];
detailsLb = (UILabel*)[cell viewWithTag:DETAILS_TEXT];
}
ObjectInfo* obj = [myList objectAtIndex:indexPath.row ] ;
nameLb.text = [obj name];
// cell.textLabel.textColor = [UIColor whiteColor];
// cell.textLabel.font = [UIFont boldSystemFontOfSize:17];
double distance = [ProjUtil getDistanceWithLat1:currentLocation.latitude long1:currentLocation.longitude lat2:obj.location.latitude long2:obj.location.longitude];
detailsLb.text = [NSString stringWithFormat:#"%.2f miles", [ProjUtil kmToMi:distance]];
// cell.detailTextLabel.textColor = [UIColor whiteColor];
// cell.detailTextLabel.font = [UIFont systemFontOfSize:15];
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
[cell setBackgroundColor:[UIColor clearColor]];
///[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
return cell;
}
When you create the label you are positioning them with this line:
detailsLb = [[[UILabel alloc] initWithFrame:CGRectMake(5, 45, 250, 20)] autorelease];
This sets the frame of your label. CGRectMake is a function that gives you a CGRect, in this case with origin (5,45), width 250 and height 20.
If you want to move the labels over to the right, increase the x value of your frame (the 5 in the CGRectMake call above).
(Givin one of my code ,widout modifying sry)
I am not able to see the image but you should create a custom cell and you can set the frames of your controls of cell in method:-
-(void)layoutSubviews
{
}
sample code :-
#import <UIKit/UIKit.h>
#interface CustomizedCellProductDetails : UITableViewCell {
UILabel *sNO;
UILabel *abcWine;
UILabel *redWine;
UILabel *two;
UILabel *hundred;
UILabel *fourTwo;
UILabel *twoOne;
UIImageView *imgView;
UILabel *itemNo;
UILabel *itemName;
UILabel *itemDesc;
UILabel *department;
UILabel *qtyAvailable;
UIButton *check;
}
#property (nonatomic , retain) UILabel *sNO;
#property (nonatomic , retain) UILabel *abcWine;
#property (nonatomic , retain) UILabel *redWine;
#property (nonatomic , retain) UILabel *two;
#property (nonatomic , retain) UILabel *hundred;
#property (nonatomic , retain) UILabel *fourTwo;
#property (nonatomic , retain) UILabel *twoOne;
#property (nonatomic , retain) UIImageView *imgView;
#property (nonatomic , retain) UILabel *itemNo;
#property (nonatomic , retain) UILabel *itemName;
#property (nonatomic , retain) UILabel *itemDesc;
#property (nonatomic , retain) UILabel *department;
#property (nonatomic , retain) UILabel *qtyAvailable;
#property (nonatomic , retain) UIButton *check;
-(void) clicked;
#end
#import "CustomizedCellProductDetails.h"
#implementation CustomizedCellProductDetails
#synthesize sNO,abcWine,redWine,two,hundred,fourTwo,twoOne,imgView,itemNo,itemName,itemDesc,department,qtyAvailable,check;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
sNO=[[UILabel alloc] init];
abcWine=[[UILabel alloc] init];
redWine=[[UILabel alloc] init];
two=[[UILabel alloc] init];
hundred=[[UILabel alloc] init];
fourTwo=[[UILabel alloc] init];
twoOne=[[UILabel alloc] init];
imgView=[[UIImageView alloc] init];
itemNo=[[UILabel alloc] init];
itemName=[[UILabel alloc] init];
itemDesc=[[UILabel alloc] init];
department=[[UILabel alloc]init];
qtyAvailable=[[UILabel alloc] init];
check=[UIButton buttonWithType:UIButtonTypeCustom];
[check addTarget:self action:#selector(clicked) forControlEvents:UIControlEventTouchUpInside];
[check setTitle:#"Check" forState:UIControlStateNormal];
[self.contentView addSubview:sNO];
[self.contentView addSubview:abcWine];
[self.contentView addSubview:redWine];
[self.contentView addSubview:two];
[self.contentView addSubview:hundred];
[self.contentView addSubview:fourTwo];
[self.contentView addSubview:twoOne];
[self.contentView addSubview:itemNo];
[self.contentView addSubview:itemName];
[self.contentView addSubview:itemDesc];
[self.contentView addSubview:department];
[self.contentView addSubview:qtyAvailable];
[self.contentView addSubview:check];
}
return self;
}
- (void)layoutSubviews {
[super layoutSubviews];
CGRect contentRect = self.contentView.bounds;
CGFloat boundsX = contentRect.origin.x;
CGRect frame;
frame=CGRectMake(boundsX+10, 0, 50, 40);
sNO.frame = frame;
frame= CGRectMake(boundsX+70 ,0, 150, 40);
abcWine.frame = frame;
frame= CGRectMake(boundsX+230 ,0, 150, 40);
redWine.frame = frame;
frame= CGRectMake(boundsX+390 ,0, 50, 40);
two.frame = frame;
frame= CGRectMake(boundsX+450 ,0, 50, 40);
hundred.frame = frame;
frame= CGRectMake(boundsX+510 ,0, 50, 40);
fourTwo.frame = frame;
frame= CGRectMake(boundsX+570 ,0, 50, 40);
twoOne.frame = frame;
/************************ ***********************/
frame= CGRectMake(boundsX+10 ,50, 100, 200);
imgView.frame = frame;
}
-(void) clicked
{
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state.
}
- (void)dealloc {
[super dealloc];
}
#end
also change the height in cellForRowAtIndexPath delegate method of uitableviewcell.
When generating your cell in cellForRowAtIndexPath, update your creation of the labels with this code to set the frames correctly
nameLb = [[[UILabel alloc] initWithFrame:CGRectMake(bgImage.frame.origin.x + bgImage.frame.size.width + 5, 5, 250, 40)] autorelease];
detailsLb = [[[UILabel alloc] initWithFrame:CGRectMake(bgImage.frame.origin.x + bgImage.frame.size.width + 5, 5, 250, 40)] autorelease];
That will dynamically create your custom rows text to the right of the image.
i have a problem with my app crashing when my custom TableViewCell gets released.
the Cell gets initialized like the following in cellForRowAtIndexPath:
SearchTableViewCell *cell = (SearchTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[SearchTableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
cell.nameLabel.text = #"some text";
cell.addressLabel.text = #"some more text";
the cell class itself looks like this
#import <UIKit/UIKit.h>
#class EGOImageView;
#interface SearchTableViewCell : UITableViewCell {
UILabel *nameLabel;
UILabel *addressLabel;
EGOImageView *imageView;
}
#property (nonatomic, retain) UILabel *nameLabel;
#property (nonatomic, retain) UILabel *addressLabel;
- (UILabel *)labelWithColor:(UIColor*)color selectedColor:(UIColor*)selectedColor fontSize:(CGFloat)fontSize bold:(BOOL)bold frame:(CGRect)rect;
- (void)setThumb:(NSString*)thumb;
#end
.m
#import "SearchTableViewCell.h"
#import "EGOImageView.h"
#import "UIView+Additions.h"
#implementation SearchTableViewCell
#synthesize nameLabel = _nameLabel, addressLabel = _addressLabel;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if ((self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])) {
// Initialization code
UIView *myContentView = self.contentView;
// Name
_nameLabel = [self labelWithColor:[UIColor blackColor] selectedColor:[UIColor whiteColor] fontSize:16.0f bold:YES frame:CGRectMake(140.0f, 16.0f, 181.0f, 21.0f)];
[myContentView addSubview:_nameLabel];
[_nameLabel release];
// Adress
_addressLabel = [self labelWithColor:[UIColor blackColor] selectedColor:[UIColor whiteColor] fontSize:13.0f bold:YES frame:CGRectMake(140.0f, _nameLabel.bottom, 181.0f, 21.0f)];
[myContentView addSubview:_addressLabel];
[_addressLabel release];
// Image
imageView = [[EGOImageView alloc] initWithPlaceholderImage:[UIImage imageNamed:#"placeholder.png"]];
imageView.frame = CGRectMake(9.0f, 9.0f, 120.0f, 80.0f);
[myContentView addSubview:imageView];
[imageView release];
}
return self;
}
- (UILabel *)labelWithColor:(UIColor*)color selectedColor:(UIColor*)selectedColor fontSize:(CGFloat)fontSize bold:(BOOL)bold frame:(CGRect)rect {
UIFont *font;
if(bold) {
font = [UIFont boldSystemFontOfSize:fontSize];
} else {
font = [UIFont systemFontOfSize:fontSize];
}
UILabel *label = [[UILabel alloc] initWithFrame:rect];
label.backgroundColor = [UIColor clearColor];
label.textColor = color;
label.highlightedTextColor = selectedColor;
label.font = font;
return label;
}
- (void)setThumb:(NSString*)thumb {
imageView.imageURL = [NSURL URLWithString:thumb];
}
- (void)willMoveToSuperview:(UIView *)newSuperview {
[super willMoveToSuperview:newSuperview];
if(!newSuperview) {
[imageView cancelImageLoad];
}
}
- (void)dealloc {
[_addressLabel release];
[_nameLabel release];
[imageView release];
[super dealloc];
}
#end
does anybody have an idea why my app crashes on releasing such a cell? commenting out the 2 labels and the image view on dealloc method, the app doesn't crash, but then there will be a memory leak right?
thanks for all hints! please leave a comment if something is unclear!
imageView is being released twice, once when it is created:
imageView = [[EGOImageView alloc] initWithPlaceholderImage:[UIImage imageNamed:#"placeholder.png"]];
imageView.frame = CGRectMake(9.0f, 9.0f, 120.0f, 80.0f);
[myContentView addSubview:imageView];
[imageView release];
and once in dealloc:
- (void)dealloc {
[_addressLabel release];
[_nameLabel release];
[imageView release];
[super dealloc];
}
You already release the memory for that labels after adding to view,again you are trying to release memory those objects are already relese in dealloc method that's why it is killing.if you remove 3 statements in dealloc method it will not crash.
I think the Problem is that you release your properties direct in the initWithStyle function and additional to that in dealloc again. Try removing the release from initWithStyle:
Furthermore you named your variables without _ in the interface but with _ #synthesize'ing in the implementation
I'm kinda stuck trying to see why, when I use this custom UIView to show a row of 3 x UILabels, that whilst I see the outline in RED for the frame, I don't see anything inside the frame. That is the labels don't appear, nor does the black border for the UILabels which I've set.
Can anyone spot an issue here?
#import <UIKit/UIKit.h>
#interface LabelRowView : UIView {
UILabel *_dateLabel;
UILabel *_titleLabel;
UILabel *_locationLabel;
}
#property (nonatomic, retain) UILabel *dateLabel;
#property (nonatomic, retain) UILabel *titleLabel;
#property (nonatomic, retain) UILabel *locationLabel;
- (void)setFont:(UIFont *)newFont;
- (void)setDataWithDate:(NSString*)dateStr AndTitle:(NSString*)titleStr AndLocation:(NSString*)locationStr;
#end
// ==============================================================
#implementation LabelRowView
#synthesize dateLabel = _dateLabel;
#synthesize titleLabel = _titleLabel;
#synthesize locationLabel = _locationLabel;
- (void)setDefaultsForLabel:(UILabel*)label {
label.layer.borderColor = [UIColor blackColor].CGColor;
label.layer.borderWidth = 1.0;
label.textAlignment = UITextAlignmentLeft;
label.lineBreakMode = UILineBreakModeTailTruncation;
label.opaque = YES; // TODO: put back in for performance reasons if possible
label.backgroundColor = [UIColor clearColor];
}
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
// Initialization code
self.dateLabel = [[[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, 10, 10)] autorelease]; // Position will be updated later
self.titleLabel = [[[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, 10, 10)] autorelease]; // Position will be updated later
self.locationLabel = [[[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, 10, 10)] autorelease]; // Position will be updated later
// Set Defaults
[self setDefaultsForLabel:self.dateLabel];
[self setDefaultsForLabel:self.titleLabel];
[self setDefaultsForLabel:self.locationLabel];
self.layer.borderColor = [UIColor redColor].CGColor;
self.layer.borderWidth = 1.0;
}
return self;
}
- (void)setDataWithDate:(NSString*)dateStr AndTitle:(NSString*)titleStr AndLocation:(NSString*)locationStr {
self.dateLabel.text = dateStr;
self.titleLabel.text = titleStr;
self.locationLabel.text = locationStr;
}
- (void)setFont:(UIFont *)newFont {
self.dateLabel.font = newFont;
self.titleLabel.font = newFont;
self.locationLabel.font = newFont;
}
- (void)layoutSubviews {
[super layoutSubviews];
// Get current width for this subview
CGFloat contentViewWidth = self.frame.size.width;
CGSize maximumLabelSize = CGSizeMake(contentViewWidth, 9999);
CGFloat oneLineHeight = [#"A" sizeWithFont:self.dateLabel.font constrainedToSize:maximumLabelSize lineBreakMode:UILineBreakModeTailTruncation].height;
// Calculate Widths
CGFloat dateColumnWidth = [#"Ddd 12:22 " sizeWithFont:self.dateLabel.font constrainedToSize:maximumLabelSize lineBreakMode:UILineBreakModeTailTruncation].width;
CGFloat titleColumnWidth = (contentViewWidth - dateColumnWidth) * 2.0/3.0;
CGFloat locationColumnWidth = contentViewWidth - dateColumnWidth - titleColumnWidth;
// Date - Layout
CGRect newRect = CGRectMake(0.0, 0.0, dateColumnWidth, oneLineHeight);
self.dateLabel.frame = newRect;
// Date - Layout
newRect = CGRectMake(dateColumnWidth, 0.0, titleColumnWidth, oneLineHeight);
self.titleLabel.frame = newRect;
// Title - Layout
newRect = CGRectMake(dateColumnWidth + titleColumnWidth, 0.0, locationColumnWidth, oneLineHeight);
self.locationLabel.frame = newRect;
}
- (void)dealloc
{
[super dealloc];
}
#end
You don't seem to be adding the UILabels as subviews.
In my project i'm using a UITextField which is embedded into a plain white UIButton with rounded corners in order to create a "beautiful" text field. This code is used several times in different views so I decided to create a custom UIView for this purpose. The code for this custom UIView:
BSCustomTextField.h
#import <Foundation/Foundation.h>
#interface BSCustomTextField : UIView {
UIButton* btnTextFieldContainer;
UITextField* textField;
NSString* text;
}
#property (retain, nonatomic) UIButton* btnTextFieldContainer;
#property (retain, nonatomic) UITextField* textField;
#property (retain, nonatomic) NSString* text;
-(id)initWithPosition:(CGPoint)position;
#end
BSCustomTextField.m
#import "BSCustomTextField.h"
#import <QuartzCore/QuartzCore.h>
#implementation BSCustomTextField
#synthesize btnTextFieldContainer, textField, text;
-(id)initWithPosition:(CGPoint)position{
if (self == [super init]) {
btnTextFieldContainer = [[UIButton alloc] initWithFrame:CGRectMake(position.x, position.y, 260, 50)];
btnTextFieldContainer.backgroundColor = [UIColor whiteColor];
[[btnTextFieldContainer layer] setCornerRadius:3.];
[[btnTextFieldContainer layer] setMasksToBounds:YES];
[[btnTextFieldContainer layer] setBorderWidth:0.];
textField = [[UITextField alloc] initWithFrame:CGRectMake(10, 10, 240, 30)];
textField.backgroundColor = [UIColor whiteColor];
textField.clearButtonMode = UITextFieldViewModeAlways;
textField.returnKeyType = UIReturnKeySend;
textField.keyboardType = UIKeyboardTypeEmailAddress;
textField.font = [UIFont fontWithName:#"Helvetica-Bold" size:20.];
[btnTextFieldContainer addSubview:textField];
[self addSubview:btnTextFieldContainer];
}
return self;
}
-(void)dealloc{
[btnTextFieldContainer release];
[textField release];
[super dealloc];
}
#end
So, when using this view in the viewDidLoad of the container view (see code below) the view is properly rendered on the desired position and looks exactly as specified but it does not react on touch events and thus does not become first responder when touched.
Code:
searchTextField = [[BSCustomTextField alloc] initWithPosition:CGPointMake(30, 150)];
searchTextField.textField.placeholder = NSLocalizedString(#"lsUserName", #"");
[[(BSPlainHeaderWithBackButtonView*)self.view contentView] addSubview:searchTextField];
Calling [searchTextField.textField becomeFirstResponder] programmatically works properly and makes the keyboard to appear.
But, the interesting part is, if I embed the code of BSCustomTextField inline in my container just like this:
UIButton* btnTextFieldContainer = [[UIButton alloc] initWithFrame:CGRectMake(30, 150, 260, 50)];
btnTextFieldContainer.backgroundColor = [UIColor whiteColor];
[[btnTextFieldContainer layer] setCornerRadius:3.];
[[btnTextFieldContainer layer] setMasksToBounds:YES];
[[btnTextFieldContainer layer] setBorderWidth:0.];
searchTextField = [[UITextField alloc] initWithFrame:CGRectMake(10, 10, 240, 30)];
searchTextField.backgroundColor = [UIColor whiteColor];
searchTextField.clearButtonMode = UITextFieldViewModeAlways;
searchTextField.returnKeyType = UIReturnKeySend;
searchTextField.keyboardType = UIKeyboardTypeEmailAddress;
searchTextField.font = [UIFont fontWithName:#"Helvetica-Bold" size:20.];
searchTextField.placeholder = NSLocalizedString(#"lsUserName", #"");
[btnTextFieldContainer addSubview:searchTextField];
[[(BSPlainHeaderWithBackButtonView*)self.view contentView] addSubview:btnTextFieldContainer];
[btnTextFieldContainer release];
everything works as expected and the textfield reacts on touches. The type of the searchTextField is properly set in the header file for each case. The only difference is that in the first case I have an additional wrapping UIView on the UIButton and the UITextFiled. I have no idea what to do to make the text field to become first responder on touch.
Thanks a lot in advance,
Roman
Ok, I've got the solution. raaz's point to the UIResponder class tipped me off to the idea that there must be something wrong in the responder chain, thus I did a little research and found this topic: Allowing interaction with a UIView under another UIView in which exact the same problem is discussed.
Here is the new working code for BSCustomTextField.m
#import "BSCustomTextField.h"
#import <QuartzCore/QuartzCore.h>
#implementation BSCustomTextField
#synthesize btnTextFieldContainer, textField, text;
-(id)initWithPosition:(CGPoint)position{
if (self == [super init]) {
btnTextFieldContainer = [[UIButton alloc] initWithFrame:CGRectMake(position.x, position.y, 260, 50)];
btnTextFieldContainer.backgroundColor = [UIColor whiteColor];
[[btnTextFieldContainer layer] setCornerRadius:3.];
[[btnTextFieldContainer layer] setMasksToBounds:YES];
[[btnTextFieldContainer layer] setBorderWidth:0.];
textField = [[UITextField alloc] initWithFrame:CGRectMake(10, 10, 240, 30)];
textField.backgroundColor = [UIColor whiteColor];
textField.clearButtonMode = UITextFieldViewModeAlways;
textField.returnKeyType = UIReturnKeySend;
textField.keyboardType = UIKeyboardTypeEmailAddress;
textField.font = [UIFont fontWithName:#"Helvetica-Bold" size:20.];
[btnTextFieldContainer addSubview:textField];
[self addSubview:btnTextFieldContainer];
}
return self;
}
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event {
// UIView will be "transparent" for touch events if we return NO
return YES;
}
-(void)dealloc{
[btnTextFieldContainer release];
[textField release];
[super dealloc];
}
#end
Since the clickable area fills out the entire BSCustomTextField view we can simply return YES in pointInside:withEvent:
Thank you all for pointing me into the right direction.
Refer UIResponder class
This class has instance method becomeFirstResponder: & isFirstResponder:
Also do not forget to set textfield editing property to YES
Oh, you're completely wrong with doing this way. You should add stretchable image into UIImageView and put it below UITextField.
UIImage *backgroundImage = [[UIImage imageNamed:#"fieldBackground.png"] stretchableImageWithLeftCapWidth:12.0 topCapHeight:0.0];
Or you can try to disable userInteraction in UIButton.