zoukankan      html  css  js  c++  java
  • ios 重用UI部分代码的好方法(再也不用为局部变量的命名而烦恼啦!)

    重用控件类代码的一个非常好的解决方案:所有一样的控件其名字均用同样的一个名字。只是在最后赋值的时候,将创建好的控件赋给我们需要用到的那个控件。
    
    
    - (id)initWithFrame:(CGRect)frame arrowImageName:(NSString *)arrow textColor:(UIColor *)textColor  {
        if((self = [super initWithFrame:frame])) {
            
            self.autoresizingMask = UIViewAutoresizingFlexibleWidth;
            self.backgroundColor = [UIColor colorWithRed:226.0/255.0 green:231.0/255.0 blue:237.0/255.0 alpha:1.0];
    
            UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, frame.size.height - 30.0f, self.frame.size.width, 20.0f)];
            label.autoresizingMask = UIViewAutoresizingFlexibleWidth;
            label.font = [UIFont systemFontOfSize:12.0f];
            label.textColor = textColor;
            label.shadowColor = [UIColor colorWithWhite:0.9f alpha:1.0f];
            label.shadowOffset = CGSizeMake(0.0f, 1.0f);
            label.backgroundColor = [UIColor clearColor];
            label.textAlignment = UITextAlignmentCenter;
            [self addSubview:label];
            _lastUpdatedLabel=label;
            [label release];
            
            label = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, frame.size.height - 48.0f, self.frame.size.width, 20.0f)];
            label.autoresizingMask = UIViewAutoresizingFlexibleWidth;
            label.font = [UIFont boldSystemFontOfSize:13.0f];
            label.textColor = textColor;
            label.shadowColor = [UIColor colorWithWhite:0.9f alpha:1.0f];
            label.shadowOffset = CGSizeMake(0.0f, 1.0f);
            label.backgroundColor = [UIColor clearColor];
            label.textAlignment = UITextAlignmentCenter;
            [self addSubview:label];
            _statusLabel=label;
            [label release];
  • 相关阅读:
    原码、反码、补码,计算机中负数的表示
    java 解惑系列
    (转载) 深入JVM学习笔记-安全性
    理解Java对象序列化
    关于Arrays.asList 函数的一些 陷阱
    JAVA设计模式之单例模式 (转载)
    Educational Codeforces Round 76 D
    总结
    bzoj3531: [Sdoi2014]旅行 (树链剖分 && 动态开点线段树)
    bzoj3626: [LNOI2014]LCA (树链剖分)
  • 原文地址:https://www.cnblogs.com/ygm900/p/3179984.html
Copyright © 2011-2022 走看看