如何设置按钮的背景颜色 - xcode

时间:2016-12-10 09:55:40

标签: ios iphone xcode uibutton

如何在Xcode中设置UIButton的背景颜色?

我在布局属性中看到了属性Background和Image,但我无法在这两个中设置任何内容。 (我只能在两种颜色中设置图像)

3 个答案:

答案 0 :(得分:42)

只需在Attribute Inspector中滚动一下,您就可以在Background部分找到view属性,以便为backgroundColor设置UIButton

enter image description here

如果要以编程方式设置按钮的backgroundColor

目标C:

 self.yourButton.backgroundColor = [UIColor redColor];

Swift 3和Swift 4

 self.yourButton.backgroundColor = UIColor.red

Swift 2.3或更低

 self.yourButton.backgroundColor = UIColor.redColor()

答案 1 :(得分:7)

如果您正在使用Objective-C,那么这是设置按钮背景颜色的代码。

UIButton

enter image description here

您可以直接从故事板中设置DECLARE @Condition varchar(max) = --insert value here declare @startedstatus uniqueidentifier = --insert value here DECLARE @Clarification uniqueidentifier = --insert value here DECLARE @Completed uniqueidentifier = --insert value here declare @Clarification uniqueidentifier = (select StatusID from MasterStatus where Name=('OnHold') --remove this from funtion so it only executes once SELECT DISTINCT J.ReceivedOn ReceivedOn ,CONVERT(varchar(10), J.ReceivedOn, 20) AS ReceivedDate ,UF.Name Facility ,UT.Name [Type] ,C.CaseNumber Batch ,C.ACHA ACHA ,J.Noofaccounts ,[AssignedDate] = (SELECT TOP 1 Convert(varchar(10), AssignedDate, 20) FROM AssignedCase WHERE CaseID = AC.CaseID ORDER BY AssignedDate DESC) ,[BatchStartdate] = Convert(varchar(10), (select top 1 StatusOnUTC from log_CaseStatus where CaseID = C.CaseID and StatusID=@startedstatus order by StatusOnUTC asc),20) ,[AccountProcessed]=(select COUNT(*) from Account ACC inner join log_AccountStatus LA on LA.AccountID = ACC.AccountId where ACC.CaseId = C.CaseID and LA.StatusID=@Completed) --,[ClarificationLog] =(select dbo.[Exat_GetClarificationCount](C.CaseID)) --REMOVE FUNCTION FROM STORED PROCEDURE ,[ClarificationLog] =(select COUNT(DISTINCT LA.AccountID) from log_AccountStatus LA inner join Account A on A.AccountID = LA.AccountID where LA.StatusID=@Clarification and A.CaseId = C.CaseId) ,[Status] = (select Name from [MasterStatus] where StatusId = (select [dbo].[GetStatusIdByCaseID](C.CaseID))) ,[Reviewer] =(select SUBSTRING((SELECT ( ',' + DisplayName) from um_user where UserID in (select UserID from AssignedCase where CaseID = C.CaseID and [Type] in('DC','Demo','Charges'))FOR XML PATH('')), 2, 1000)) ,[Auditor] =(select SUBSTRING((SELECT ( ',' + DisplayName) from um_user where UserID in (select ValidatedBy from Account where Validated = 1 and CaseID = C.CaseID)FOR XML PATH('')), 2, 1000)) ,[AuditCount] = (select Count(*) from Account where CaseID = C.CaseID) ,[Errors] = (select Count(*) from log_AccountError LA inner join Account ACO on ACO.AccountID = LA.AccountID where ACO.CaseID = C.CaseID) from [Job] J inner join [Case] C on J.JobID = C.JobID inner join log_casestatus lcs on lcs.caseid=c.caseid inner join [Account] A on C.CaseID = A.CaseID inner join [AssignedCase] AC on AC.CaseID = C.CaseID inner join um_Facility UF on UF.FacilityID = J.FacilityID inner join um_Type UT on UT.TypeID = J.TypeID inner join log_AccountStatus LA on LA.AccountID = A.AccountID ; 的背景颜色,如下所示:

enter image description here

答案 2 :(得分:6)

Swift 2.3

    btn.backgroundColor = UIColor(red: 17.0/255.0, green: 119.0/255.0, blue: 151.0/255.0, alpha: 1.0)
    btn.backgroundColor = UIColor.redColor()

在故事板中 enter image description here