Code Monkey home page Code Monkey logo

Comments (2)

spicyShrimp avatar spicyShrimp commented on July 17, 2024

只是我定义的一个生成按钮的方法而已
+(UIBarButtonItem *)itemWithTarget:(id)target
action:(SEL)action
nomalImage:(UIImage *)nomalImage
higeLightedImage:(UIImage *)higeLightedImage
imageEdgeInsets:(UIEdgeInsets)imageEdgeInsets {

UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
[button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];

[button setImage:[nomalImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
if (higeLightedImage) {
    [button setImage:higeLightedImage forState:UIControlStateHighlighted];
}
[button sizeToFit];
if (button.bounds.size.width < 40) {
    CGFloat width = 40 / button.bounds.size.height * button.bounds.size.width;
    button.bounds = CGRectMake(0, 0, width, 40);
}
if (button.bounds.size.height > 40) {
    CGFloat height = 40 / button.bounds.size.width * button.bounds.size.height;
    button.bounds = CGRectMake(0, 0, 40, height);
}
button.imageEdgeInsets = imageEdgeInsets;
return [[UIBarButtonItem alloc] initWithCustomView:button];

}

你可以根据实际情况进行调整

from uinavigation-sxfixspace.

spicyShrimp avatar spicyShrimp commented on July 17, 2024

比如设置button.imageView.contentModel
比如设置button的大小

from uinavigation-sxfixspace.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.