Changing color of IBAction with FlatUIKit? - ios

I am trying to changing the visual aspects of my button, however I am trying to use the FlatUIKit's button aspect, for those who don't know what that is that ok as it doesn't matter, in the example project that they provide they change the color of an IBOutlet button however it dosen't work the same with an IBAction heres their example code:
#import "ViewController.h"
#import "FUIButton.h"
#import "UIColor+FlatUI.h"
#interface ViewController ()
#property (weak, nonatomic) IBOutlet FUIButton *alertViewButton;
//as you can see its a FUIButton, and I'm not sure how to use that with an IBAction
#end
#implementation ViewController
- (void)viewDidLoad
{
self.alertViewButton.buttonColor = [UIColor peterRiverColor];
self.alertViewButton.shadowColor = [UIColor silverColor];
self.alertViewButton.shadowHeight = 3.0f;
self.alertViewButton.cornerRadius = 6.0f;
self.alertViewButton.titleLabel.font = [UIFont boldFlatFontOfSize:16];
[self.alertViewButton setTitleColor:[UIColor cloudsColor] forState:UIControlStateNormal];
[self.alertViewButton setTitleColor:[UIColor cloudsColor] forState:UIControlStateHighlighted];
}
Heres my code this far:
my .h
#import <UIKit/UIKit.h>
#interface HomeViewController : UIViewController {
}
- (IBAction)start:(id)sender;
#end
my .m:
#import "HomeViewController.h"
#import "UIColor+FlatUI.h"
#import "FUIButton.h"
#interface HomeViewController ()
#end
#implementation HomeViewController
- (IBAction)start:(id)sender {
//this is the button i want change the appearance of.
}
I am stuck with this, the button I want to use the FUIButton color effects is the IBAction called start, any help? Thanks in advance.
Note: I am using storyboards if that makes a difference.

Related

How to change variable of custom UIView from ViewController

I have created a custom UIView (ProgressView) where I draw a shape imported via StyleKit from PaintCode.
Below are the codes. I have declared instance variable property in my custom UIView and when I try to change property from ViewController, It does not work.
ProgressView.h
#import <UIKit/UIKit.h>
#interface ProogressView : UIView
#property (nonatomic) float daysFraction;
#property (nonatomic) float pagesFraction;
#end
ProgressView.m
#import "ProgressView.h"
#import "StyleKitName.h"
#import "ViewController.h"
#implementation ProgressView
#synthesize daysFraction = _daysFraction;
#synthesize pagesFraction = _pagesFraction;
- (void)drawRect:(CGRect)rect {
// Drawing code
[StyleKitName drawCanvas1WithDaysFraction:self.daysFraction pageFraction:self.pagesFraction];
}
-(void)awakeFromNib {
[super awakeFromNib];
self.pagesFraction = 0;
self.daysFraction = 0;
}
ViewController.h
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController
#end
*ViewController.m**
#import "ViewController.h"
#import "ButtonAnimation.h"
#import "ProgressView.h"
#import "StyleKitName.h"
#interface ViewController ()
#property (weak, nonatomic) IBOutlet ButtonAnimation *buttonView;
#property (weak, nonatomic) IBOutlet UIButton *actionButton;
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
ProgressView *new =[[ ProgressView alloc]init];
new.daysFraction = 0.7f; // here I am setting value to variable in custom view ProgressView but not working.
}
- (IBAction)animateTheButton:(id)sender {
self.buttonView.layer.backgroundColor = [UIColor clearColor].CGColor;
[self.buttonView addErrorAnimation];
}
#end
You need to add this view to UIViewController's view:
[self.view addSubview:progressView];
Later, you must also set a frame. Eg
[progressView setFrame:self.view.bounds];
You may do it in viewDid/WillLayoutSubviews method to change it on rotation / window resize event.
BTW, do not name your view as new, it's horrible. Such name doesn't even tell what kind of variable is it.

how to set navigationBar color by calling a method?

I created a CommonMethod subclass of NSObject for customizing UINavigationBar here is the CommonMethod.h and CommonMethod.m files
CommonMethod.h
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#interface CommonMethods : NSObject
+(void)setNavBackButton:(id)viewController;
+(void)setNavBackground:(id)viewController Color:(UIColor *)color;
#end
CommonMethod.h
#import <UIKit/UIKit.h>
#import "CommonMethods.h"
#implementation CommonMethods
+(void)setNavBackground:(id)viewController Color:(UIColor *)color
{
UIViewController *controller = (id)viewController;
controller.navigationController.navigationBar.backgroundColor=[UIColor redColor];
}
#end
Now when I am calling [CommonMethods setNavBackground:self Color:[UIColor redColor]; it is executing the method but didn't change anything on UI. Can anyone expalin this what I am missing ?
Edit :
I also tried controller.navigationController.navigationBar.barTintColor = color;
You have minor Mistake on Code
+(void)setNavBackground:(id)viewController Color:(UIColor *)color
{
UIViewController *controller = (id)viewController;
controller.navigationController.navigationBar.barTintColor = color; // Change NavigationBar color to Red
}
Call Method like this:[CommonMethod setNavBackground:self Color:[UIColor redColor]];

Objective C Transparent UIViewController for Gameover Screen

Information: I would like to make a little Game (Not Important what kind of game) with a little Game Over Screen.
Because i cant Upload Images, i try to Describe it.
You Play, everything is alright. Then you get Gameover. The Screen should be the Same and an Overlayer is Showing the Score (Transparent / Alpha)
Now my First Question is: Is my Solution good?
I use one UIViewController from the Storyboard
Source:
ViewController.h
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController
{
IBOutlet UIButton *btnTest;
}
-(IBAction)btnTestClick;
#end
ViewController.m
#import "ViewController.h"
#import "MeinGottEh.h"
#interface ViewController ()
#end
#implementation ViewController
-(void)btnTestClick
{
self.modalPresentationStyle = UIModalPresentationCurrentContext;
MeinGottEh *sampleView = [[MeinGottEh alloc] init];
sampleView.labelText = #"High: 123";
[sampleView setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
[self presentModalViewController:sampleView animated:YES];
}
#end
Then the Second UIViewController (External File, not in Storyboard)
MeinGottEh.h
#import <UIKit/UIKit.h>
#interface MeinGottEh : UIViewController
{
IBOutlet UIButton *btnClose;
}
-(IBAction)btnCloseClick;
#property(nonatomic) NSString *labelText;
#end
MeinGottEh.m
#import "MeinGottEh.h"
#interface MeinGottEh ()
#end
#implementation MeinGottEh
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor clearColor];
[btnClose setTitle:self.labelText forState:UIControlStateNormal];
}
-(void)btnCloseClick
{
[self dismissModalViewControllerAnimated:YES];
}
#end
Is this Solution to Open a Highscore Box good? If no, please tell me how to do it (I make a Research on Stackoverflow. Thats the Most Parts)
If Yes: How can i make it Transparent?
Thank you very much.

Action when pressing return key on keyboard (iOS)

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[self checkRun:nil];
return YES;
}
I'm trying to complete the IBAction checkRun when the return key is pressed, by using the above code, but it doesn't seem to be working. Where am I going wrong? I thought maybe it's because I'm not directly referencing the textfield that I'm typing in, but I can't work out where I'd need to put the name of that textfield.
Thanks in advance.
ViewController.h:
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController <UITextFieldDelegate>
#end
ViewController.m:
#import "ViewController.h"
#interface ViewController ()
#property (nonatomic, strong) UITextField *textField;
#end
#implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.textField.delegate = self;
}
This UITextfield subclass enables you to set a condition for the text and dynamically change the UIReturnKey:
https://github.com/codeinteractiveapps/OBReturnKeyTextField

Return to mainview from subview

Basically I want to remove my subview when a button is pressed, here is my code, please tell me what should I add.
I have created a view based application and following are the codes:
//My file name is poo1
//This is poo1ViewController.h file
#import <UIKit/UIKit.h>
#interface poo1ViewController : UIViewController
{
IBOutlet UIButton *fl;
}
#property (nonatomic,retain) UIButton *fl;
-(IBAction) ifl:(id)sender;
#end
This is poo1ViewController.m file
#import "poo1ViewController.h"
#implementation poo1ViewController
#synthesize fl;
-(IBAction) ifl:(id) sender {
UIViewController* flipViewController = [[UIViewController alloc] initWithNibName:#"flip" bundle:[NSBundle mainBundle]];
[self.view addSubview:flipViewController.view];
}
Now similarly I have added a UIViewController Subclass called "flip" with xib. And in flip.h I have added the below code
#import <UIKit/UIKit.h>
#interface flip : UIViewController
{
IBOutlet UIButton *bb;
}
#property (nonatomic,retain)UIButton *bb;
-(IBAction)ss:(id)sender;
#end
And in flip.m
#import "flip.h"
#implementation flip
#synthesize bb;
-(IBAction)ss:(id)sender
{
//What do I need to add here to return to previous view when button is pressed.
}
When this bb button is pressed, it should act as back button, how to implement it.
just add [self removeFromSuperview]; to your method ss:
Note however that this does not dealloc the view from the memory. It's just not showing!

Resources