iOS 修改UIProgressView的高度,自定义UIProgressView

iOS 修改UIProgressView的高度,自定义UIProgressView

高仿系统UIProgressView,支持调节高度
初始化

首先去GitHub下载GGProgressView

#import "GGProgressView.h"

//初始化
//高度就是frame设定的高度,自由设置
GGProgressView *progressView=[[GGProgressView alloc]initWithFrame:CGRectMake(10, 100, self.view.bounds.size.width-20, 30)];
//设置
progressView
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
iOS 中,可以使用 Objective-C 自定义 TabBar。下面是一个简单的步骤: 1. 创建一个继承自 UITabBarController 的类,例如 MyTabBarController。 2. 在 MyTabBarController.m 中,实现 viewDidLoad 方法,在其中创建自定义 TabBar。 ```objc - (void)viewDidLoad { [super viewDidLoad]; // 创建自定义 TabBar MyTabBar *myTabBar = [[MyTabBar alloc] init]; myTabBar.delegate = self; [self setValue:myTabBar forKey:@"tabBar"]; } ``` 3. 在 MyTabBarController.m 中,实现 UITabBarDelegate 协议中的方法,例如 tabBar:didSelectItem:,处理 TabBar 点击事件。 ```objc - (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item { // 处理 TabBar 点击事件 } ``` 4. 创建一个继承自 UITabBar 的类,例如 MyTabBar。 5. 在 MyTabBar.m 中,实现 layoutSubviews 方法,在其中布局 TabBar。 ```objc - (void)layoutSubviews { [super layoutSubviews]; // 布局 TabBar } ``` 6. 在 MyTabBar.m 中,实现 drawRect: 方法,在其中绘制 TabBar。 ```objc - (void)drawRect:(CGRect)rect { // 绘制 TabBar } ``` 7. 在 MyTabBar.m 中,实现 touchUpInside 方法,在其中处理 TabBar 点击事件。 ```objc - (void)touchUpInside:(UIButton *)button { // 处理 TabBar 点击事件 } ``` 8. 在 MyTabBar.m 中,添加 TabBar 上的按钮,例如: ```objc - (void)layoutSubviews { [super layoutSubviews]; // 添加 TabBar 上的按钮 UIButton *button1 = [UIButton buttonWithType:UIButtonTypeCustom]; button1.frame = CGRectMake(0, 0, self.frame.size.width / 4, self.frame.size.height); [button1 addTarget:self action:@selector(touchUpInside:) forControlEvents:UIControlEventTouchUpInside]; [self addSubview:button1]; UIButton *button2 = [UIButton buttonWithType:UIButtonTypeCustom]; button2.frame = CGRectMake(self.frame.size.width / 4, 0, self.frame.size.width / 4, self.frame.size.height); [button2 addTarget:self action:@selector(touchUpInside:) forControlEvents:UIControlEventTouchUpInside]; [self addSubview:button2]; UIButton *button3 = [UIButton buttonWithType:UIButtonTypeCustom]; button3.frame = CGRectMake(self.frame.size.width / 2, 0, self.frame.size.width / 4, self.frame.size.height); [button3 addTarget:self action:@selector(touchUpInside:) forControlEvents:UIControlEventTouchUpInside]; [self addSubview:button3]; UIButton *button4 = [UIButton buttonWithType:UIButtonTypeCustom]; button4.frame = CGRectMake(self.frame.size.width * 3 / 4, 0, self.frame.size.width / 4, self.frame.size.height); [button4 addTarget:self action:@selector(touchUpInside:) forControlEvents:UIControlEventTouchUpInside]; [self addSubview:button4]; } ``` 9. 在 MyTabBar.m 中,重写 setItems:animated: 方法,在其中设置 TabBar 上按钮的图标和标题。 ```objc - (void)setItems:(NSArray<UITabBarItem *> *)items animated:(BOOL)animated { [super setItems:items animated:animated]; // 设置 TabBar 上按钮的图标和标题 for (int i = 0; i < items.count; i++) { UITabBarItem *item = items[i]; UIButton *button = self.subviews[i + 1]; [button setImage:item.image forState:UIControlStateNormal]; [button setTitle:item.title forState:UIControlStateNormal]; [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; } } ``` 以上就是使用 Objective-C 自定义 TabBar 的简单步骤。当然,还可以根据需求进行更详细的定制。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值