zoukankan      html  css  js  c++  java
  • iOS第一个Demo

    appdelegate.m:

    //
    //  AppDelegate.m
    //  wzy_ios_demo
    //
    //  Created by admin on 2020/12/8.
    //
    
    #import "AppDelegate.h"
    #import "MyUiView.h"
    #import "ViewController.h"
    @interface AppDelegate ()
    
    @end
    
    @implementation AppDelegate
    
    
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
        self.window = [[UIWindow alloc] initWithFrame:
                 [[UIScreen mainScreen] bounds]];
        
        //画全屏的灰色背景
        CGRect firstFrame = self.window.bounds;
        MyUiView *firstView = [[MyUiView alloc]                  initWithFrame:firstFrame];
        firstView.backgroundColor = [UIColor grayColor];
        [self.window addSubview:firstView];
        self.window.backgroundColor = [UIColor whiteColor];
        [self.window makeKeyAndVisible];
        
        ViewController *controller = [ViewController new];
        [controller.view addSubview: firstView];
        
        self.window.rootViewController = controller;
        return YES;
    }
    
    @end

    MyUiView.m:

    //
    //  MyUiView.m
    //  wzy_ios_demo
    //
    //  Created by admin on 2020/12/8.
    //
    
    #import "MyUiView.h"
    
    @interface MyUiView ()  //分类
    
    @property (strong, nonatomic) UIColor *circleColor;
    
    @end
    
    @implementation MyUiView
    
    -(instancetype) initWithFrame:(CGRect)frame {
        self = [super initWithFrame: frame];
        if (self) {
            self.backgroundColor = [UIColor clearColor];
            self.circleColor = [UIColor greenColor];
            self.userInteractionEnabled = YES;
        }
        
        return self;
    }
    
    -(void) drawRect:(CGRect)rect {
        CGRect bounds = self.bounds;
        CGPoint center;
        center.x = bounds.origin.x + bounds.size.width / 2.0;
        center.y = bounds.origin.y + bounds.size.height / 2.0;
        float radius = MIN(bounds.size.width, bounds.size.height) / 2.0;    //取小的,防止竖屏能放下但横屏放不下
        UIBezierPath *path = [[UIBezierPath alloc] init];
        [path addArcWithCenter: center radius: radius startAngle: 0 endAngle: 2.0 * M_PI clockwise: YES];
        path.lineWidth = 20;
        [self.circleColor setStroke];
        [path stroke];
    }
    
    -(void) setCircleColor:(UIColor *)circleColor {
        _circleColor = circleColor;
        [self setNeedsDisplay];
    }
    
    -(void) touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
        NSLog(@"%@ was touched", self);
        float red = (arc4random() % 100) / 100.0;
        float blue = (arc4random() % 100) / 100.0;
        float green = (arc4random() % 100) / 100.0;
        UIColor *randomColor = [UIColor colorWithRed: red green:green blue:blue alpha: 1.0];
        
        self.circleColor = randomColor;
    }
    @end

    效果:

  • 相关阅读:
    装饰器 、迭代器,json,pickle,hash
    装饰器知识
    python 编码问题处理
    大数据组件服务的启动与关闭命令
    网站数据统计分析之一:日志收集原理及其实现
    style资源搜索
    分享5个超实用的办公资源网站,错过就可惜了!
    资源搜索
    七大顶级资源
    hive工具bin下的schematool的作用
  • 原文地址:https://www.cnblogs.com/FdWzy/p/14107538.html
Copyright © 2011-2022 走看看