iOS中UIKit——UIButton設置邊框


UIButton *testButton = [UIButton buttonWithType:UIButtonTypeSystem];

    [testButton setFrame:CGRectMake(self.view.frame.size.width/2, self.view.frame.size.height/2, 100, 100)];

    [testButton setTitle:@"獲取屏幕尺寸" forState:UIControlStateNormal];

   

    

    [testButton.layer setMasksToBounds:YES];//設置按鈕的圓角半徑不會被遮擋

    [testButton.layer setCornerRadius:10];

    [testButton.layer setBorderWidth:2];//設置邊界的寬度

    

    //設置按鈕的邊界顏色

    CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB();

    CGColorRef color = CGColorCreate(colorSpaceRef, (CGFloat[]){1,0,0,1});

    [testButton.layer setBorderColor:color];

    

    

    [testButton addTarget:self action:@selector(touch) forControlEvents:UIControlEventTouchUpInside];

    [self.view addSubview:testButton];

   

  實現效果:

    

 


 

我的CSDN博客地址:http://blog.csdn.net/qw963895582/article


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM