//1.圓形圖片 uiimageview *headimage = [[uiimageviewalloc] initwithimage:[uiimageimagenamed:@"portrait_bg_80"]]; headimage.frame = cgrectmake(imagetop.frame.origin.x+10, imagetop.frame.origin.y+10, 35, 35); //將radius設置為長度或者寬度的一半就可以實現圓形的圖片 headimage.layer.cornerradius = 35/2.0; headimage.layer.maskstobounds = yes; [headimage.layer setborderwidth:1]; [headimage.layersetbordercolor:[uicolorwhitecolor].cgcolor];
//必須在uiimageview加載之後設置 //設置圖片為圓角的 calayer *imagelayer = [cell.userpicview layer]; //獲取imageview的層 [imagelayer setmaskstobounds:yes]; [imagelayer setcornerradius:6.0]; //uiview圓角 viewt.layer.cornerradius = 10;//設置那個圓角的有多圓 iewt.layer.borderwidth = 10;//設置邊框的寬度,當然可以不要 viewt.layer.bordercolor = [[uicolor redcolor] cgcolor];//設置邊框的顏色 viewt.layer.maskstobounds = yes;
1.//用畫圖的方式設置圓角 mimageview.image=[uiimage imagenamed:@"bg1.png"]; mimageview.frame=cgrectmake(center.x-radius, center.y-radius, 2*radius, 2*radius); mimageview.layer.cornerradius=radius;//設置圓角半徑 mimageview.layer.maskstobounds=yes; [mimageview.layer setborderwidth:1];//設置邊框寬度 [mimageview.layer setbordercolor:[uicolor whitecolor].cgcolor];//設置邊框顏色 [self addsubview:mimageview];
imageview.contentMode = UIViewContentModeScaleAspectFit;