一、竞技场搭建--UISegmentedControl的使用
// 重写 自定义控制器的view
- (void)loadView
{
UIImageView *imgView = [[UIImageView alloc] initWithFrame:ChaosScreenBounds]; imgView.image = [UIImage imageNamed:@"NLArenaBackground"];
imgView.userInteractionEnabled = YES; self.view = imgView;
} - (void)viewDidLoad {
[super viewDidLoad]; UISegmentedControl *seg = [[UISegmentedControl alloc] initWithItems:@[@"足球",@"篮球"]];
// 设置宽度
seg.width += ;
// 默认选中第一个
seg.selectedSegmentIndex = ; // 设置的文字颜色
seg.tintColor = ChaosRGB(, , ); // 设置选中后文字颜色
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
dict[NSForegroundColorAttributeName] = [UIColor whiteColor];
[seg setTitleTextAttributes:dict forState:UIControlStateSelected]; // 设置背景图片
[seg setBackgroundImage:[UIImage imageNamed:@"CPArenaSegmentBG"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
// 设置选中后的图片
[seg setBackgroundImage:[UIImage imageNamed:@"CPArenaSegmentSelectedBG"] forState:UIControlStateSelected barMetrics:UIBarMetricsDefault]; self.navigationItem.titleView = seg; // // 设置导航控制器navBar的背景图片,,这里是有导航VC的子控制器修改了,不符合封装的思想
// UIImage *image = [UIImage imageNamed:@"NLArenaNavBar64"];
// image = [image stretchableImageWithLeftCapWidth:image.size.width * 0.5 topCapHeight:image.size.height * 0.5];
//
// [self.navigationController.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault]; }
二、搭建发现中的合买--storyboard和代码混合开发
- 重定义按钮,改变按钮中图片和label的顺序。layoutSubviews方法默认会调用两次,这样位置就会出现偏差,如图黄色框框为偏差
@implementation ChaosTitleView #pragma mark - 重新排列按钮内部空间的顺序,原始顺序:图片左,文字右 需求:图片右,文字左
- (void)layoutSubviews
{
[super layoutSubviews];
// layoutSubviews这个方法会来两次,第一次变成自己所需求的。但是第二次来又变了一次,这里判断一下
if (self.titleLabel.x > self.imageView.x) { // 思路,改变x坐标
self.titleLabel.x = self.imageView.x;
self.imageView.x = CGRectGetMaxX(self.titleLabel.frame); }
} @end
三、搭建发现中的幸运选号
--在storyboard中设置红框框中的属性,只能隐藏系统中的TabBar,但是项目中的是自定义的,
--解决办法,自定义TabBar的同时,不要把系统的移除。直接把自定义的加到系统的上面。在viewWillAppear方法中移除系统自带的按钮
--幸运选号的界面背景是张图片,不需要下面的导航条,设置了push后隐藏后,出现push完了之后,还有隐藏导航条的动画问题。以下是点击幸运选号瞬间的截图
--解决办法,自定义背景View,把图片画上去
--图片做动画的方法
--幸运选号界面布局--站位思想。最后将view的alpha设置为0。但是有时候还是会出现,push完后,下面导航条的动画消失,导致整个界面重新布局,代码如下
// 如果有storyboard,需要在这里布局子控件位置,因为storyboard会先调用updateViewConstraints布局storyboard描述的位置,等它描述完,我们在布局下。
// 如果使用storyboard,在viewDidLoad使用frame布局是不准确的。
- (void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews]; CGFloat screenH = [UIScreen mainScreen].bounds.size.height;
CGFloat screenW = [UIScreen mainScreen].bounds.size.width; CGFloat x = ;
CGFloat w = ;
CGFloat h = ;
int cols = ;
NSUInteger count = self.btns.count;
NSUInteger rows = (count - ) / cols + ;
CGFloat margin = (screenH - rows * ) / (rows + );
int col = ;
int row = ;
int i = ;
CGFloat y = ;
for (UIButton *btn in _btns) {
col = i % cols;
row = i / cols;
y = (margin + h) * row + margin;
if (col == ) {
x = ;
}else{
x = screenW - w;
}
btn.frame = CGRectMake(x, y, w, h); i++;
} }
四、我的彩票界面
--重点是按钮图片被拉伸的不好看。通过鼠标点击设置如下界面,没有效果
--解决方法,拿到按钮,在viewDidLoad方法中获取按钮当前背景图片,并拉伸