自定义Button 图片在上面文字在下面

本文介绍了一个自定义按钮类buttonCustom的实现方式,包括设置标题、图片及对应的布局位置等内容。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#import "buttonCustom.h"
#define KimageW 30
#define KtitleH 21
#define Kpadding 10
@interface buttonCustom()

@end

@implementation buttonCustom

- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        self.titleLabel.textAlignment = NSTextAlignmentCenter;
    }
    return self;
}

//set title
- (void)setTitle:(NSString *)title forState:(UIControlState)state{
    [super setTitle:title forState:state];
   
}

//set image
- (void)setImage:(UIImage *)image forState:(UIControlState)state
{
    [super setImage:image forState:state];
    
}


//custom title rect
- (CGRect)titleRectForContentRect:(CGRect)contentRect{
    return CGRectMake(0 , Kpadding *2 , self.bounds.size.width, 21 );
}

//custom image rect
- (CGRect)imageRectForContentRect:(CGRect)contentRect{
    return CGRectMake(0 , Kpadding ,self.bounds.size.width , KimageW);
}
@end

 

转载于:https://www.cnblogs.com/Mantis-man/p/5104656.html

u-swiper 是一个 Vue.js 组件,用于创建漂亮的滑块轮播图。您可以使用它来展示图片文字、视频等内容。 要自定义 u-swiper 的内容,您需要先了解它的结构。u-swiper 由一个或多个 u-swiper-slide 组件组成,每个 u-swiper-slide 表示一个轮播项。默认情况下,u-swiper-slide 只能包含一个图片或视频。但是,您可以在 u-swiper-slide 中添加任意 HTML 内容,以实现自定义样式和布局。 下面是一个简单的示例,展示如何在 u-swiper-slide 中添加自定义内容: ```html <template> <div class="u-swiper"> <u-swiper-slide> <div class="my-custom-content"> <h2>这是一个自定义标题</h2> <p>这是自定义的文本内容,可以包含任意 HTML 标签。</p> <button>自定义按钮</button> </div> </u-swiper-slide> <u-swiper-slide> <img src="https://placehold.it/800x400" alt="Slide 2"> </u-swiper-slide> <u-swiper-slide> <img src="https://placehold.it/800x400" alt="Slide 3"> </u-swiper-slide> </div> </template> <script> import { USwiper, USwiperSlide } from 'u-swiper'; export default { components: { USwiper, USwiperSlide } }; </script> <style scoped> .my-custom-content { background-color: #f1f1f1; padding: 20px; text-align: center; } </style> ``` 在上面的示例中,我们在第一个 u-swiper-slide 中添加了一个自定义的 div 元素,它包含一个标题、一段文本和一个按钮。我们还为这个 div 元素添加了一些自定义样式,以使它看起来与其他轮播项不同。 当您运行以上代码时,您会看到第一个轮播项中的自定义内容已经生效了。您可以通过添加更多自定义 HTML 内容来创建更丰富的轮播项。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值