logo
down
shadow

Modifying UIButton Programmatically


Modifying UIButton Programmatically

By : user2955021
Date : November 22 2020, 10:33 AM
should help you out Use func setBackgroundImage(_:, forState:) instead of func setImage(_:, forState:), in addition, I would use func titleForState(:) instead of titleLabel?.text.
code :
@IBAction func StartandStop(sender: AnyObject) {
    let title = StartandStop.titleForState(UIControlState.Normal)
    if title? == "Start Flight" {
        StartandStop.setTitle("Stop Flight", forState: UIControlState.Normal)
        StartandStop.setBackgroundImage(UIImage(named: "End"), forState: .Normal)
    }
    else if title? == "Stop Flight" {
        StartandStop.setTitle("Start Flight", forState: UIControlState.Normal)
        StartandStop.setBackgroundImage(UIImage(named: "Start"), forState: .Normal)
    }
}


Share : facebook icon twitter icon
Modifying a UIButton width with animation

Modifying a UIButton width with animation


By : user3406224
Date : March 29 2020, 07:55 AM
seems to work fine Here is my code , , Tested code 100% works
connect each method with specified
code :
-(IBAction)expand{//touch down


    NSLog(@"expand");

    [UIView transitionWithView:but duration:0.0 options:UIViewAnimationOptionTransitionNone animations:^(void) {


        CGRect newRect = but.frame;

        CGPoint ce= but.center;
        newRect.size.width *= 5;

        but.frame = newRect;    

        but.center=ce;



    } completion:^(BOOL finished) {



    }];


}

 -(IBAction)shrink{//touch up inside
    NSLog(@"shrink");


    [UIView transitionWithView:but duration:0.0 options:UIViewAnimationOptionTransitionNone animations:^(void) {


        CGRect newRect = but.frame;

        CGPoint ce= but.center;
        newRect.size.width /= 5;

        but.frame = newRect;    

        but.center=ce;



    } completion:^(BOOL finished) {



    }];


}
Tap UIButton to create another UIButton programmatically

Tap UIButton to create another UIButton programmatically


By : Cox
Date : March 29 2020, 07:55 AM
I hope this helps . If you plain add a lot of buttons use UITableView with custom cell. If you will just add new buttons to view you will get a performance issue - all you buttons will be loaded simultaneously. UITableView can manage this situation and unload unused cell's.
Modifying UIButton's alpha property from another class

Modifying UIButton's alpha property from another class


By : brijesh
Date : March 29 2020, 07:55 AM
will be helpful for those in need In your code, an instance of ViewController is alloced and inited, and the method setAlphaToButton is called on it. Then the view controller is released because you have no object retaining it. That's why you don't see any effect; the ViewController instance you call the method on never appears on screen.
It's not clear how your code is supposed to work; do you have an instance of ViewController in existence when tapDetected is called? If this is the case, and this is the ViewController whose button you want to alter the alpha of, then you need to have a reference to that instance of ViewController and call setAlphaToButton on it.
How to resize UIButton without modifying its hit rectangle

How to resize UIButton without modifying its hit rectangle


By : BANOTHU ASHOK RAJ SI
Date : March 29 2020, 07:55 AM
this one helps. As you've rightly observed, overriding setHighlighted: to change the transform of the button causes a kind of vicious loop. So don't do that! Instead, override backgroundRectForBounds:, like this:
code :
- (CGRect)backgroundRectForBounds:(CGRect)bounds {
    CGRect result = [super backgroundRectForBounds:bounds];
    if (self.highlighted)
        result = CGRectInset(result, -3, -3);
    return result;
}
How to display a popover programmatically from a uibutton that is also created programmatically (Not using interface bui

How to display a popover programmatically from a uibutton that is also created programmatically (Not using interface bui


By : kekgab
Date : March 29 2020, 07:55 AM
I wish this help you I think this code will help you. You are certainly missing delegate methods
Related Posts Related Posts :
  • Swift/iOS: How to access Object properties when type-casted from Protocol?
  • consecutive statement need to have ; error in swift
  • Trying to create a 32 bpc NSBitmapImageRep, getting hit with errors
  • Does locationManager:didUpdateLocations: method called at the same time in extension and its containing app
  • Can't get Data using SwiftyJSON
  • Convert String to UnsafeMutablePointer<char_t> in Swift
  • inout param with empty object since nil won't work
  • How to align a mask onto an image
  • compiler forcing self inside static method of a function while using dispatch_sync
  • private static variable in struct
  • Conditional "in" for arrays in Swift
  • Extension for Double to accept String as initializer in Swift
  • Pass type to generic function and compare
  • How to customise the look of the PFSignUpViewController
  • How to take screen shot programmatically (Swift, SpriteKit)
  • Setting NavigationController's NavigationBar translucent property to false causes extra padding
  • Create multiple UIViews when the user taps the screen
  • Filter Array of [AnyObject] in Swift
  • How to add ParseUI to a swift project
  • Can Swift enums have multiple raw values?
  • Using a function() variable in a different Class - Swift
  • Masking an image in Swift using CALayer and UIImage
  • KVC without NSObject (NSPredicate)
  • Any? to Dictionary Cast and retrieving value
  • NSCharacterSet.characterIsMember() with Swift's Character type
  • SCNScene: Calculate projected size of an object
  • How to use contains on a swiftyJSON object
  • Index of element in sorted()
  • How do I initialise a new NSDocument instance in Swift?
  • Multiple functions with the same name
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org