I have 2 textfields. On startup I can switch between lbl and lbl2. But after the first click only lbl is working, you have to tap 10(+/-) times on lbl2 before the cursor goes to that textfield. Whats going on?
- (void)viewWillAppear:(BOOL)animated
{
UITextField *lbl = [[UITextField alloc] initWithFrame:CGRectMake(24, 397, 266, 30)];
[lbl setPlaceholder:#"E-mailadres"];
[lbl setValue:[UIColor whiteColor] forKeyPath:#"_placeholderLabel.textColor"];
[lbl setBackgroundColor:[UIColor clearColor]];
lbl.textColor = [UIColor whiteColor];
[[self view] addSubview:lbl];
CALayer* layer = [lbl layer];
CALayer *bottomBorder = [CALayer layer];
bottomBorder.borderColor = [UIColor whiteColor].CGColor;
bottomBorder.borderWidth = 1;
bottomBorder.frame = CGRectMake(-1, layer.frame.size.height-1, layer.frame.size.width, 1);
[bottomBorder setBorderColor:[UIColor whiteColor].CGColor];
[layer addSublayer:bottomBorder];
UITextField *lbl2 = [[UITextField alloc] initWithFrame:CGRectMake(24, 450, 266, 30)];
[lbl2 setPlaceholder:#"Wachtwoord"];
[lbl2 setValue:[UIColor whiteColor] forKeyPath:#"_placeholderLabel.textColor"];
[lbl2 setBackgroundColor:[UIColor clearColor]];
lbl2.textColor = [UIColor whiteColor];
lbl2.secureTextEntry = YES;
[[self view] addSubview:lbl2];
CALayer* layer2 = [lbl2 layer];
CALayer *bottomBorder2 = [CALayer layer];
bottomBorder2.borderColor = [UIColor whiteColor].CGColor;
bottomBorder2.borderWidth = 1;
bottomBorder2.frame = CGRectMake(-1, layer2.frame.size.height-1, layer2.frame.size.width, 1);
[bottomBorder2 setBorderColor:[UIColor whiteColor].CGColor];
[layer2 addSublayer:bottomBorder2];
UIButton *myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
myButton.frame = CGRectMake(24, 500, 266, 30); // position in the parent view and set the size of the button
[myButton setTitle:#"INLOGGEN" forState:UIControlStateNormal];
[myButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
// add targets and actions
// add to a view
[[self view] addSubview:myButton];
CALayer *layer3 = myButton.layer;
layer3.backgroundColor = [[UIColor whiteColor] CGColor];
layer3.borderColor = [[UIColor whiteColor] CGColor];
layer3.borderWidth = 1.0f;
layer3.opacity = 0.6;
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(keyboardDidShow:) name:UIKeyboardDidShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(keyboardDidHide:) name:UIKeyboardDidHideNotification object:nil];
}
It appears neither text field was given a delegate. I'm not sure you can use them without one - I never tried. If you don't have a delegate how would you dismiss the keyboard at the end of the editing session?
Related
I am creating a UIButton similar to this image:
I tried it by using following code:
+(void)createShadowOnView:(UIView *)view color:(UIColor *)color width:(CGFloat)width height:(CGFloat)height shadowOpacity:(CGFloat)shadowOpacity andShadowRadius:(CGFloat)radius{
view.layer.masksToBounds = NO;
view.layer.shadowColor = color.CGColor;
view.layer.shadowOffset = CGSizeMake(width,height);
view.layer.shadowOpacity = shadowOpacity;
[view.layer setShadowRadius:radius];
}
I was able to achieve this:
I want shadow effect on Button to be kept only on bottom part.
How can I achieve desired effect.
Maybe you should set view's backgroundcolor, so the title has no shadow, you can set view.layer.shadowOffset to change the shadow size.
UIButton *customBTn = [UIButton buttonWithType:UIButtonTypeCustom];
customBTn.backgroundColor = [UIColor whiteColor];
customBTn.frame = CGRectMake(100, 100, 200, 50);
[customBTn setTitle:#"Sign Up" forState:UIControlStateNormal];
[customBTn setTitleColor:[UIColor colorWithRed:1/255.0 green:168/255.0 blue:244/255.0 alpha:1.0] forState:UIControlStateNormal];
customBTn.layer.borderColor = [UIColor colorWithRed:1/255.0 green:168/255.0 blue:244/255.0 alpha:1.0].CGColor;
customBTn.layer.borderWidth = 2;
customBTn.layer.cornerRadius = 25;
customBTn.layer.shadowColor = [UIColor lightGrayColor].CGColor;
customBTn.layer.shadowOffset = CGSizeMake(0,8);
customBTn.layer.shadowOpacity = 0.9;
[self.view addSubview:customBTn];
Output :-
Only issue with your code is you missed to set background colour for your sign up button. Use this code,
self.signUpButton.backgroundColor = [UIColor whiteColor];
[UIView createShadowOnView:self.signUpButton color:[UIColor lightGrayColor] width:0 height:2 shadowOpacity:0.3 andShadowRadius:0];
Preview:
Code:
UIButton *buttonWithShadow = [UIButton buttonWithType:UIButtonTypeCustom];
[buttonWithShadow setFrame:CGRectMake(10.0f, 10.0f, 300.0f, 50.0f)];
[buttonWithShadow setTitle:#"SIGN UP" forState:UIControlStateNormal];
[buttonWithShadow setTitle:#"SIGN UP" forState:UIControlStateHighlighted];
[buttonWithShadow.titleLabel setFont:[UIFont boldSystemFontOfSize:15.0f]];
[buttonWithShadow setTitleColor:[UIColor colorWithRed:1.0f/255.0 green:168.0f/255.0 blue:244.0f/255.0 alpha:1.0f] forState:UIControlStateNormal];
[buttonWithShadow setBackgroundColor:[UIColor whiteColor]];
[buttonWithShadow.layer setBorderColor:[UIColor colorWithRed:1.0f/255.0 green:168.0f/255.0 blue:244.0f/255.0 alpha:1.0f].CGColor];
[buttonWithShadow.layer setBorderWidth:2.0f];
[buttonWithShadow.layer setCornerRadius:(buttonWithShadow.frame.size.height / 2.0f)];
[buttonWithShadow.layer setShadowColor:[UIColor lightGrayColor].CGColor];
[buttonWithShadow.layer setShadowOpacity:0.3f];
[buttonWithShadow.layer setShadowRadius:0.0f];
[buttonWithShadow.layer setShadowOffset:CGSizeMake(0.0f,2.0f)];
[buttonWithShadow.layer setMasksToBounds:NO];
[self.view addSubview:buttonWithShadow];
I am using custom cell and headerView with static images and footerView but not scrolling as smoothly as it should scroll, it is getting stuck in middle and then scrolls........
Header
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
UIView *headerview = [[UIView alloc]init];
if (section == 2) {
headerview.frame = CGRectMake(0, 30, tableView.frame.size.width, 117);
Button = [[UIButton alloc]initWithFrame:CGRectMake(0, 18, headerview.frame.size.width, 100)];
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(5, 0, tableView.frame.size.width, 17)];
label.text = #"Siddharth and hiren Like this";
label.font = [UIFont systemFontOfSize:10];
label.textColor = [UIColor blackColor];
[headerview addSubview:label];
}
else
{
headerview.frame = CGRectMake(0, 0, tableView.frame.size.width, 100);
Button = [[UIButton alloc]initWithFrame:headerview.frame];
}
// sheap top left and top right
UIBezierPath *maskPath;
maskPath = [UIBezierPath bezierPathWithRoundedRect:headerview.bounds
byRoundingCorners:(UIRectCornerTopLeft|UIRectCornerTopRight)
cornerRadii:CGSizeMake(7.0, 7.0)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
headerview.frame = headerview.bounds;
maskLayer.path = maskPath.CGPath;
headerview.layer.mask = maskLayer;
// shape for button bottom
headerview.backgroundColor = [UIColor whiteColor];
CALayer *bottomBorder = [CALayer layer];
bottomBorder.frame = CGRectMake(0.0f, 0, headerview.frame.size.width, 1);
bottomBorder.backgroundColor = [UIColor colorWithRed:217/255.0f green:217/255.0f blue:217/255.0f alpha:1].CGColor;
bottomBorder.shadowColor = [[UIColor blackColor] CGColor];
bottomBorder.shadowOpacity = 0.9f;
bottomBorder.shadowRadius = 0.3f;
[headerview.layer addSublayer:bottomBorder];
headerview.layer.shouldRasterize = YES;
// Button Imageview
UIImageView *buttonimg = [[UIImageView alloc]initWithFrame:Button.bounds];
buttonimg.image = [UIImage imageNamed:[_SecImgArray objectAtIndex:section]];
buttonimg.layer.shouldRasterize = YES;
[Button addSubview:buttonimg];
// imageview overlay
UIView *overlay = [[UIView alloc]initWithFrame:Button.bounds];
overlay.alpha = 0.3;
overlay.backgroundColor = [UIColor blackColor];
overlay.layer.shouldRasterize = YES;
[buttonimg addSubview:overlay];
[Button addTarget:self action:#selector(Expand: and:) forControlEvents:UIControlEventTouchUpInside];
Button.tag = section;
if ([[AllNewsdic objectForKey:#"posts"] count] == 0) {
[Button setTitle:[[[DownloadData objectForKey:#"posts"]objectAtIndex:section]objectForKey:#"title"] forState:UIControlStateNormal];
}
else
{
[Button setTitle:[[[AllNewsdic objectForKey:#"posts"]objectAtIndex:section]objectForKey:#"title"] forState:UIControlStateNormal];
}
[Button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
Button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
Button.contentVerticalAlignment = UIControlContentVerticalAlignmentBottom;
Button.contentEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
Button.titleLabel.lineBreakMode = NSLineBreakByWordWrapping;
Button.titleLabel.numberOfLines = 0;
Button.titleLabel.font = [UIFont fontWithName:#"Avenir-Black" size:12];
Button.layer.shadowColor = [UIColor greenColor].CGColor;
Button.layer.shadowOpacity = 0.4;
Button.layer.shadowRadius = 1.0f;
Button.layer.cornerRadius = 7;
Button.layer.masksToBounds = YES;
Button.layer.shouldRasterize = YES;
[headerview addSubview:Button];
return headerview;}
Footer
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
UIView *fotter = [[UIView alloc]initWithFrame:CGRectMake(0, -10, tableView.frame.size.width, 30)];
fotter.backgroundColor = [UIColor whiteColor];
// corner redius
UIBezierPath *maskPath;
maskPath = [UIBezierPath bezierPathWithRoundedRect:fotter.bounds
byRoundingCorners:(UIRectCornerBottomLeft|UIRectCornerBottomRight)
cornerRadii:CGSizeMake(7.0, 7.0)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
fotter.frame = fotter.bounds;
maskLayer.path = maskPath.CGPath;
// maskLayer.backgroundColor = [UIColor colorWithRed:217/255.0f green:217/255.0f blue:217/255.0f alpha:1].CGColor;
fotter.layer.mask = maskLayer;
// Bottom layer
CALayer *bottomBorder = [CALayer layer];
bottomBorder.frame = CGRectMake(0.0f, 32, fotter.frame.size.width, 2);
bottomBorder.backgroundColor = [UIColor blackColor].CGColor;
[fotter.layer addSublayer:bottomBorder];
// top Layer
CALayer *topLayer = [CALayer layer];
topLayer.frame = CGRectMake(13, 0, fotter.frame.size.width - 26, 0.7);
topLayer.backgroundColor = [UIColor colorWithRed:197/255.0f green:187/255.0f blue:188/255.0f alpha:1].CGColor;
topLayer.shadowOpacity = 0.6f;
topLayer.shadowRadius = 0.5f;
[fotter.layer addSublayer:topLayer];
// Like bUtton
likebutton = [[UIButton alloc]initWithFrame:CGRectMake(0, -3, fotter.frame.size.width/2, fotter.frame.size.height + 3)];
likebutton.titleLabel.font = [UIFont systemFontOfSize:10];
likebutton.titleLabel.tintColor = [UIColor colorWithRed:197/255.0f green:187/255.0f blue:188/255.0f alpha:1];
[likebutton addTarget:self action:#selector(like:) forControlEvents:UIControlEventTouchUpInside];
[likebutton setTitle:#"1 likes" forState:UIControlStateNormal];
likebutton.tag = section;
like = [[UIImageView alloc]initWithFrame:CGRectMake(40 ,8, 15, 15)];
like.image = [UIImage imageNamed:#"SimpleLike.png"];
[likebutton addSubview:like];
[likebutton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
[fotter addSubview:likebutton];
// Follow Button
NSLog(#"%f",fotter.frame.size.width/2 + 1);
follow = [[UIButton alloc]initWithFrame:CGRectMake(fotter.frame.size.width/2 , -3, fotter.frame.size.width/2, fotter.frame.size.height + 3)];
follow.titleLabel.font = [UIFont systemFontOfSize:10];
follow.titleLabel.tintColor = [UIColor colorWithRed:197/255.0f green:187/255.0f blue:188/255.0f alpha:1];
[follow setTitle:#"Follow" forState:UIControlStateNormal];
followimage = [[UIImageView alloc]initWithFrame:CGRectMake(35 ,8, 17, 17)];
followimage.image = [UIImage imageNamed:#"Follow.png"];
[follow addSubview:followimage];
[follow setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
follow.tag = section;
[follow addTarget:self action:#selector(Follow:) forControlEvents:UIControlEventTouchUpInside];
[fotter addSubview:follow];
return fotter;}
Cell
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
AllNewsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"AllNews"];
cell.one.text = [one objectAtIndex:indexPath.section];
cell.two.text = [two objectAtIndex:indexPath.section];
cell.three.text = [three objectAtIndex:indexPath.section];
[cell.three sizeToFit];
return cell;}
how to set tableview scroll smooth and effective
how to set interface properties
tableview data is static
Use reusable UITableViewCell inside function viewForHeaderInSection and inside viewForFooterInSection
Do not create the new UIView and buttons for each function call.
Your table view scrolling is not smooth because the views inside viewForHeaderInSection and viewForFooterInSection methods are allocated multiple times. Why ? Because whenever you scroll up and down, both the methods are called as and when required.
Check whether header view is already allocated. If it is nil, then and then allocate it and return it. Otherwise, just return it. Same way in case of footer view.
Add comment in case of any doubt..
I need a solution for the problem described below..
I have a scenario where a view needs to be shown only on ipad but it needs to be hidden on iphone. The way the view is built is as follows:
The below code shows the view on ipad. I want to hide this view when loaded on iphone.
How can this be achieved?
(void)viewDidLoad
{
[super viewDidLoad];
gotQuoteList = NO;
isExpanded = NO;
heightOfUploadManager = 282;
freqQuotesArray = [[NSMutableArray alloc] init];
selectedCheckboxes = [[NSMutableDictionary alloc] init];
serviceConfig_G_Obj = [[ServiceConfig alloc] init];
cacheManager_G_Obj = [[CacheManager alloc] init];
[self.view setBackgroundColor: [[UIColor whiteColor] colorWithAlphaComponent:0.5f]];
[self observeRotationChanges];
uploadMngrView = [[UIView alloc] init];
[self setUploadManagerFrame];
[uploadMngrView setBackgroundColor:[self colorWithHexString:#"EFEFEF"]];
uploadMngrView.layer.borderColor = [self colorWithHexString:#"C7C7C7"].CGColor;
uploadMngrView.layer.borderWidth = 1.0;
[self.view addSubview:uploadMngrView];
UIView *titleLblBgView = [[UIView alloc] init];
[titleLblBgView setFrame:CGRectMake(0, 40, 512, 1)];
[titleLblBgView setBackgroundColor:[self colorWithHexString:#"C7C7C7"]];
[uploadMngrView addSubview:titleLblBgView];
UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 1, 512-21, 38)];
[titleLabel setText:#"Upload Document"];
[titleLabel setTextAlignment:NSTextAlignmentLeft];
[titleLabel setBackgroundColor:[self colorWithHexString:#"EFEFEF"]];
[titleLabel setTextColor:[self colorWithHexString:#"656565"]];
[titleLabel setFont:[UIFont fontWithName:#"Arial" size:21]];
[uploadMngrView addSubview:titleLabel];
UILabel *fileLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 60, 141, 34)];
[fileLabel setText:#"File"];
[fileLabel setBackgroundColor:[self colorWithHexString:#"EFEFEF"]];
[fileLabel setTextColor:[self colorWithHexString:#"656565"]];
[fileLabel setFont:[UIFont fontWithName:#"Arial" size:14]];
[uploadMngrView addSubview:fileLabel];
UILabel *fileNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(163, 60, 329, 34)];
[fileNameLabel setBackgroundColor: [UIColor colorWithPatternImage:[UIImage imageNamed:#"labelBG.png"]]];
[fileNameLabel setTextColor:[self colorWithHexString:#"656565"]];
[fileNameLabel setText:[NSString stringWithFormat:#" %#",[[self getFileName] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
[fileNameLabel setFont:[UIFont fontWithName:#"Arial" size:14]];
fileNameLabel.layer.borderColor = [self colorWithHexString:#"C7C7C7"].CGColor;
fileNameLabel.layer.borderWidth = 1.0;
[uploadMngrView addSubview:fileNameLabel];
UILabel *destinationLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 114, 141, 34)];
[destinationLabel setTextColor:[self colorWithHexString:#"656565"]];
[destinationLabel setText:#"Destination"];
[destinationLabel setBackgroundColor:[self colorWithHexString:#"EFEFEF"]];
[destinationLabel setFont:[UIFont fontWithName:#"Arial" size:14]];
[uploadMngrView addSubview:destinationLabel];
UILabel *destinationNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(163, 114, 329, 34)];
destinationNameLabel.tag = 1;
UITapGestureRecognizer *worksaceRBTapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(didTapRadioBtnLabelWithGesture:)];
worksaceRBTapGestureRecognizer.numberOfTapsRequired = 1;
[destinationNameLabel setUserInteractionEnabled:YES];
[destinationNameLabel addGestureRecognizer:worksaceRBTapGestureRecognizer];
destinationNameLabel.layer.borderColor = [self colorWithHexString:#"C7C7C7"].CGColor;
destinationNameLabel.layer.borderWidth = 1.0;
[destinationNameLabel setText:#" My Workspace"];
[destinationNameLabel setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:#"labelBG.png"]]]; [destinationNameLabel setTextColor:[self colorWithHexString:#"656565"]];
[destinationNameLabel setFont:[UIFont fontWithName:#"Arial" size:14]];
[uploadMngrView addSubview:destinationNameLabel];
myWorkspaceRadioBtn = [UIButton buttonWithType:UIButtonTypeCustom];
myWorkspaceRadioBtn.tag = 1;
[myWorkspaceRadioBtn setImage:[UIImage imageNamed:#"radiobtn_off.png"] forState:UIControlStateNormal];
[myWorkspaceRadioBtn setImage:[UIImage imageNamed:#"radiobtn_on.png"] forState:UIControlStateSelected];
[myWorkspaceRadioBtn setFrame:CGRectMake(166, 121, 26, 22)];
myWorkspaceRadioBtn.selected=YES;
[myWorkspaceRadioBtn addTarget:self action:#selector(radioButton:) forControlEvents:UIControlEventTouchUpInside];
[uploadMngrView addSubview:myWorkspaceRadioBtn];
UILabel *destinationQuoteLabel = [[UILabel alloc] initWithFrame:CGRectMake(163, 147, 329, 34)];
destinationQuoteLabel.tag = 2;
UITapGestureRecognizer *quotelistRBTapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(didTapRadioBtnLabelWithGesture:)];
quotelistRBTapGestureRecognizer.numberOfTapsRequired = 1;
[destinationQuoteLabel setUserInteractionEnabled:YES];
[destinationQuoteLabel addGestureRecognizer:quotelistRBTapGestureRecognizer];
destinationQuoteLabel.layer.borderColor = [self colorWithHexString:#"C7C7C7"].CGColor;
destinationQuoteLabel.layer.borderWidth = 1.0;
[destinationQuoteLabel setTextColor:[self colorWithHexString:#"656565"]];
[destinationQuoteLabel setFont:[UIFont fontWithName:#"Arial" size:14]];
[destinationQuoteLabel setText:#" Link to selected quote"];
[destinationQuoteLabel setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:#"labelBG.png"]]];
[uploadMngrView addSubview:destinationQuoteLabel];
quoteListRadioBtn = [UIButton buttonWithType:UIButtonTypeCustom];
quoteListRadioBtn.tag = 2;
[quoteListRadioBtn setImage:[UIImage imageNamed:#"radiobtn_off.png"] forState:UIControlStateNormal];
[quoteListRadioBtn setImage:[UIImage imageNamed:#"radiobtn_on.png"] forState:UIControlStateSelected];
[quoteListRadioBtn setFrame:CGRectMake(166, 152, 26, 22)];
[quoteListRadioBtn addTarget:self action:#selector(radioButton:) forControlEvents:UIControlEventTouchUpInside];
[uploadMngrView addSubview:quoteListRadioBtn];
[self fillQuoteListScrollView];
lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 202, 512, 1)];
lineView.backgroundColor = [self colorWithHexString:#"C7C7C7"];
[uploadMngrView addSubview:lineView];
cancelButton = [UIButton buttonWithType:UIButtonTypeCustom];
[cancelButton setFrame:CGRectMake(20, 222, 231, 40)];
[cancelButton.titleLabel setFont:[UIFont boldSystemFontOfSize:14]];
[cancelButton setTitleColor:[self colorWithHexString:#"656565"] forState:UIControlStateNormal];
[cancelButton setTitle:#"Cancel" forState:UIControlStateNormal];
CAGradientLayer *cancelBtnGradient = [CAGradientLayer layer];
cancelBtnGradient.frame = cancelButton.bounds;
cancelBtnGradient.colors = [NSArray arrayWithObjects:(id)[[UIColor colorWithRed:255.0/255.0f green:255.0/255.0f blue:255.0/255.0f alpha:1.0f] CGColor], (id)[[UIColor colorWithRed:238.0/255.0f green:238.0/255.0f blue:238.0/255.0f alpha:1.0f] CGColor], nil];
[cancelButton.layer insertSublayer:cancelBtnGradient atIndex:0];
cancelButton.layer.borderColor = [self colorWithHexString:#"C7C7C7"].CGColor;
cancelButton.layer.borderWidth = 1.0;
[cancelButton addTarget:self action:#selector(cancelUpload) forControlEvents:UIControlEventTouchUpInside];
[uploadMngrView addSubview:cancelButton];
uploadButton = [UIButton buttonWithType:UIButtonTypeCustom];
[uploadButton setFrame:CGRectMake(261, 222, 231, 40)];
[uploadButton.titleLabel setFont:[UIFont boldSystemFontOfSize:14]];
[uploadButton setTitleColor:[self colorWithHexString:#"55A0B9"] forState:UIControlStateNormal];
[uploadButton setTitle:#"Upload" forState:UIControlStateNormal];
CAGradientLayer *uploadBtnGradient = [CAGradientLayer layer];
uploadBtnGradient.frame = uploadButton.bounds;
uploadBtnGradient.colors = [NSArray arrayWithObjects:(id)[[UIColor colorWithRed:255.0/255.0f green:255.0/255.0f blue:255.0/255.0f alpha:1.0f] CGColor], (id)[[UIColor colorWithRed:238.0/255.0f green:238.0/255.0f blue:238.0/255.0f alpha:1.0f] CGColor], nil];
[uploadButton.layer insertSublayer:uploadBtnGradient atIndex:0];
uploadButton.layer.borderColor = [self colorWithHexString:#"C7C7C7"].CGColor;
uploadButton.layer.borderWidth = 1.0;
[uploadButton addTarget:self action:#selector(uploadDoc) forControlEvents:UIControlEventTouchUpInside];
[uploadMngrView addSubview:uploadButton];
}
You can do this like this,
uploadMngrView = [[UIView alloc] init];
[self setUploadManagerFrame];
[uploadMngrView setBackgroundColor:[self colorWithHexString:#"EFEFEF"]];
uploadMngrView.layer.borderColor = [self colorWithHexString:#"C7C7C7"].CGColor;
uploadMngrView.layer.borderWidth = 1.0;
if ([UIDevice currentDevice].userInterfaceIdom == UIUserInterfaceIdoniPad) {
[self.view addSubview:uploadMngrView];
}
HTH, Enjoy Coding !!
As your setting up the views programatically, you something like this
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
// Create the view only for ipad
self.someView = [[UIView alloc] initWithFrame:someFrame];
//Or set the view hidden just on ipad
self.someView.hidden = YES;
//Or set the view a different frame on ipad
self.someView.frame = CGRectMake(x,y,width,height);
}
else
{
//Do some non ipad layout stuff here
}
I am trying to put transparency (or a color gradient) on the title of an UIButton. I don't know how do that. I have tried to simply put a clearColor on the titleColor but we only see the background color.
So i hope that there is someone here who will be an amazing idea for my problem.
My solution
self.loginButton = [UIButton buttonWithType:UIButtonTypeCustom];
self.loginButton.backgroundColor= [UIColor whiteColor];
self.loginButton.frame = CGRectMake(self.signUpButton.left,
0,
self.signUpButton.frame.size.width,
self.signUpButton.frame.size.height);
[self.loginButton.layer setBackgroundColor:[[UIColor blackColor] CGColor]];
self.loginButton.layer.borderColor = [[UIColor whiteColor] CGColor];
self.loginButton.layer.borderWidth = 1.0f;
self.loginButton.layer.cornerRadius = 3.0f;
[self.loginButton addTarget:self action:#selector(loginButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
self.loginButtonLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
self.loginButtonLabel.font = [UIFont fontWithName:#"OpenSans-Light" size:16.0f];
self.loginButtonLabel.textColor = [UIColor whiteColor];
self.loginButtonLabel.text = #"Connexion";
[self.loginButtonLabel sizeToFit];
UIColor *topColor = [UIColor blueColor];
UIColor *bottomColor = [UIColor orangeColor];
self.gradientView = [[UIView alloc] initWithFrame:self.loginButtonLabel.frame];
[self.loginButton addSubview:self.gradientView];
[self.loginButton sendSubviewToBack:self.gradientView];
[self.loginButton addSubview:self.loginButtonLabel];
CAGradientLayer *gradient = [CAGradientLayer layer];
gradient.frame = self.gradientView.frame;
gradient.colors = [NSArray arrayWithObjects:(id)topColor.CGColor, (id)bottomColor.CGColor, nil];
gradient.startPoint = CGPointMake(0, 0.5);
gradient.endPoint = CGPointMake(1, 0.5);
[self.gradientView.layer addSublayer:gradient];
self.gradientView.layer.mask = self.loginButtonLabel.layer;
self.gradientView.layer.masksToBounds = YES;
self.gradientView.center = CGPointMake(self.loginButton.width / 2, self.loginButton.height / 2);
[self.view addSubview:self.loginButton];
But Now i need to put the gradient on the border. Any idea ?
So my solution is to create a custom button with an UILabel. I will use an UIView with a gradient for color the text.
The solution :
self.loginButton = [UIButton buttonWithType:UIButtonTypeCustom];
self.loginButton.backgroundColor= [UIColor whiteColor];
self.loginButton.frame = CGRectMake(self.signUpButton.left,
0,
self.signUpButton.frame.size.width,
self.signUpButton.frame.size.height);
[self.loginButton.layer setBackgroundColor:[[UIColor blackColor] CGColor]];
self.loginButton.layer.borderColor = [[UIColor whiteColor] CGColor];
self.loginButton.layer.borderWidth = 1.0f;
self.loginButton.layer.cornerRadius = 3.0f;
[self.loginButton addTarget:self action:#selector(loginButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
self.loginButtonLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
self.loginButtonLabel.font = [UIFont fontWithName:#"OpenSans-Light" size:16.0f];
self.loginButtonLabel.textColor = [UIColor whiteColor];
self.loginButtonLabel.text = #"Connexion";
[self.loginButtonLabel sizeToFit];
UIColor *topColor = [UIColor blueColor];
UIColor *bottomColor = [UIColor orangeColor];
self.gradientView = [[UIView alloc] initWithFrame:self.loginButtonLabel.frame];
[self.loginButton addSubview:self.gradientView];
[self.loginButton sendSubviewToBack:self.gradientView];
[self.loginButton addSubview:self.loginButtonLabel];
CAGradientLayer *gradient = [CAGradientLayer layer];
gradient.frame = self.gradientView.frame;
gradient.colors = [NSArray arrayWithObjects:(id)topColor.CGColor, (id)bottomColor.CGColor, nil];
gradient.startPoint = CGPointMake(0, 0.5);
gradient.endPoint = CGPointMake(1, 0.5);
[self.gradientView.layer addSublayer:gradient];
self.gradientView.layer.mask = self.loginButtonLabel.layer;
self.gradientView.layer.masksToBounds = YES;
self.gradientView.center = CGPointMake(self.loginButton.width / 2, self.loginButton.height / 2);
[self.view addSubview:self.loginButton];
I'm setting up a subclass of UIView to roll my own UIAlertView style view. I've got everything set up properly with displaying the view, but I'm at a bit of a loss as to how to dismiss the view properly. Specifically, when a user taps on the button in the view, it needs to animate out of the main view. This is the code for the view itself:
+ (void)showCustomAlertWithTitle:(NSString *)titleString andMessage:(NSString *)messageString inView:(UIView *)view andButton1Title: (NSString *)button1Title andButton2Title: (NSString *)button2Title
{
UIWindow *window = [[[UIApplication sharedApplication] windows] lastObject];
CGRect windowFrame = window.frame;
[view setAlpha:0.5f];
UIColor *buttonColor = [UIColor colorWithRed:0/255.0f green:130/255.0f blue:216/255.0f alpha:1];
UIColor *titleColor = [UIColor colorWithRed:0/255.0f green:153/255.0f blue:102/255.0f alpha:1];
// Shade
UILabel *shadeWindow = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, windowFrame.size.width, windowFrame.size.height)];
shadeWindow.backgroundColor = [UIColor blackColor];
shadeWindow.alpha = 0.50f;
// Define size and origin of alert box
float alertBoxHeight = 225;
float alertBoxWidth = 200;
float alertBoxXorigin = windowFrame.size.width / 2 - (alertBoxWidth / 2);
float alertBoxYorigin = windowFrame.size.height / 2 - (alertBoxHeight / 2);
// Initialize background
UIView *alertBackground = [[UIView alloc] initWithFrame:CGRectMake(alertBoxXorigin, alertBoxYorigin, alertBoxWidth, alertBoxHeight)];
alertBackground.layer.cornerRadius = 5.0f;
[alertBackground.layer setMasksToBounds:YES];
alertBackground.layer.backgroundColor = [UIColor whiteColor].CGColor;
// Title Label
UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, alertBoxWidth, 40)];
titleLabel.text = titleString;
titleLabel.textAlignment = NSTextAlignmentCenter;
titleLabel.textColor = titleColor;
titleLabel.layer.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.05f].CGColor;
[titleLabel setFont:[UIFont fontWithName:#"AvenirNext-Bold" size:20.0]];
// Title Divider
UILabel *titleDivider = [[UILabel alloc] initWithFrame:CGRectMake(0, 40, alertBoxWidth, 1.0)];
titleDivider.backgroundColor = [UIColor grayColor];
titleDivider.alpha = 0.5f;
// Alert Message Text
UITextView *alertMessage = [[UITextView alloc] initWithFrame:CGRectMake(0, 40, alertBoxWidth, alertBoxHeight - 90)];
alertMessage.text = messageString;
alertMessage.layer.backgroundColor = [UIColor whiteColor].CGColor;
[alertMessage setFont:[UIFont fontWithName:#"Avenir" size:15.0]];
alertMessage.textAlignment = NSTextAlignmentCenter;
alertMessage.textColor = [UIColor grayColor];
[alertMessage setEditable:NO];
// Button 1
UIButton *button1 = [[UIButton alloc] init];
UIButton *button2 = [[UIButton alloc] init];
[button1 addTarget:self action:#selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
if (button2Title == nil)
{
button1.frame = CGRectMake(10, alertBoxHeight - 50, alertBoxWidth - 20, 40);
}
else
{
button1.frame = CGRectMake(10, alertBoxHeight - 50, (alertBoxWidth / 2) - 20, 40);
button2.frame = CGRectMake(alertBoxWidth / 2 + 10, alertBoxHeight - 50, (alertBoxWidth / 2) - 20, 40);
}
button1.layer.backgroundColor = buttonColor.CGColor;
[button1 setTitle:button1Title forState:UIControlStateNormal];
[button1.titleLabel setFont:[UIFont fontWithName:#"AvenirNext-Bold" size:15.0f]];
button1.layer.cornerRadius = 2.5f;
[button1.layer setMasksToBounds:YES];
// Button 2
button2.layer.backgroundColor = buttonColor.CGColor;
[button2 setTitle:button2Title forState:UIControlStateNormal];
[button2.titleLabel setFont:[UIFont fontWithName:#"AvenirNext-Bold" size:15.0f]];
button2.layer.cornerRadius = 2.5f;
[button2.layer setMasksToBounds:YES];
// Bounce Implementation
alertBackground.transform = CGAffineTransformMakeScale(0.01, 0.01);
[UIView animateWithDuration:0.25 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^
{
alertBackground.transform = CGAffineTransformIdentity;
}
completion:^(BOOL finished)
{
// do something once the animation finishes, put it here
}];
[window addSubview:view];
[window addSubview:alertBackground];
[view addSubview:shadeWindow];
[view bringSubviewToFront:alertBackground];
[alertBackground addSubview:button1];
[alertBackground addSubview:titleLabel];
[alertBackground addSubview:titleDivider];
[alertBackground addSubview:alertMessage];
[alertBackground addSubview:button2];
[alertBackground bringSubviewToFront:titleDivider];
/* [[[customAlerts sharedInstance] subViewArray] addObject:alertBackground];
[[[customAlerts sharedInstance] subViewArray] addObject:view];
[[[customAlerts sharedInstance] subViewArray] addObject:window];*/
}
When button1 is tapped, for instance, I need to have it animate the view out of the superView and remove it from the stack. I'm not sure how to handle this. Does anyone have any ideas?
To permanently remove a view, I generally use the UIView instance method removeFromSuperview. followed by a line setting the relevant variable to nil:
[myAlertView removeFromSuperview];
myAlertView = nil;
In your case then, I think you need to move the view off the screen by animating the its bounds property, then use the above couple of lines to remove any references to it.
Just found the answer here:
Dismiss view controller from #selector without creating seperate method
Had to download some custom classes but it worked:
[button1 addEventHandler:^(id sender, UIEvent *event)
{
[UIView animateWithDuration:0.25f animations:^{
[alertBackground setAlpha:0.0f];
[shadeWindow setAlpha:0.0f];
[window setAlpha:0.0f];
}];
} forControlEvent:UIControlEventTouchUpInside];
Custom classes can be found here:
https://github.com/ZeR0-Wu/JTTargetActionBlock