我创建了一 strip 有灰色描边颜色的贝塞尔曲线路径。但是我需要在同一条路径上用橙色覆盖橙色,并根据要填充的路径的百分比,如 70%、80% 或任何其他值
let circlePath = UIBezierPath(arcCenter: CGPoint(x: view.frame.size.width/2,y: view.frame.size.height), radius: CGFloat(25), startAngle: CGFloat(Double.pi), endAngle:CGFloat(0), clockwise: true)
print(circlePath)
let shapeLayer = CAShapeLayer()
shapeLayer.path = circlePath.cgPath
shapeLayer.lineDashPattern = [10 ,10]
shapeLayer.fillColor = UIColor.clear.cgColor
shapeLayer.strokeColor = UIColor.white.cgColor
shapeLayer.lineWidth = 1.0
let shapeLayer1 = CAShapeLayer()
shapeLayer1.path = circlePath.cgPath
shapeLayer1.fillColor = UIColor.clear.cgColor
shapeLayer1.strokeColor = UIColor.lightGray.cgColor
shapeLayer1.lineWidth = 10
shapeLayer1.addSublayer(shapeLayer)
view.layer.addSublayer(shapeLayer1)
最佳答案
let completionPercentage = 60.0
let circlePath = UIBezierPath(arcCenter: CGPoint(x: view.frame.size.width/2,y: view.frame.size.height), radius: CGFloat(25), startAngle: CGFloat(Double.pi), endAngle:CGFloat(0), clockwise: true)
print(circlePath)
let shapeLayer = CAShapeLayer()
shapeLayer.path = circlePath.cgPath
shapeLayer.lineDashPattern = [5 ,5]
shapeLayer.fillColor = UIColor.clear.cgColor
shapeLayer.strokeColor = UIColor.white.cgColor
shapeLayer.lineWidth = 1.0
let shapeLayer1 = CAShapeLayer()
shapeLayer1.path = circlePath.cgPath
shapeLayer1.fillColor = UIColor.clear.cgColor
shapeLayer1.strokeColor = UIColor.lightGray.cgColor
shapeLayer1.lineWidth = 10
shapeLayer1.addSublayer(shapeLayer)
let angle = completionPercentage * 1.8
let circlePath1 = UIBezierPath(arcCenter: CGPoint(x: view.frame.size.width/2,y: view.frame.size.height), radius: CGFloat(25), startAngle: CGFloat(Double.pi), endAngle:CGFloat(((180 + angle)/180)*Double.pi), clockwise: true)
print(circlePath1)
let shapeLayer2 = CAShapeLayer()
shapeLayer2.path = circlePath1.cgPath
shapeLayer2.lineDashPattern = [5 ,5]
shapeLayer2.fillColor = UIColor.clear.cgColor
shapeLayer2.strokeColor = UIColor.white.cgColor
shapeLayer2.lineWidth = 1.0
let shapeLayer3 = CAShapeLayer()
shapeLayer3.path = circlePath1.cgPath
shapeLayer3.fillColor = UIColor.clear.cgColor
shapeLayer3.strokeColor = UIColor.orange.cgColor
shapeLayer3.lineWidth = 10
shapeLayer3.addSublayer(shapeLayer2)
view.layer.addSublayer(shapeLayer1)
view.layer.addSublayer(shapeLayer3)
输出:-
关于swift - 根据百分比填充描边颜色,即 80%、70% 或任何其他百分比,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43626735/
我试图在一个项目中使用rake,如果我把所有东西都放到Rakefile中,它会很大并且很难读取/找到东西,所以我试着将每个命名空间放在lib/rake中它自己的文件中,我添加了这个到我的rake文件的顶部:Dir['#{File.dirname(__FILE__)}/lib/rake/*.rake'].map{|f|requiref}它加载文件没问题,但没有任务。我现在只有一个.rake文件作为测试,名为“servers.rake”,它看起来像这样:namespace:serverdotask:testdoputs"test"endend所以当我运行rakeserver:testid时
我正在寻找执行以下操作的正确语法(在Perl、Shell或Ruby中):#variabletoaccessthedatalinesappendedasafileEND_OF_SCRIPT_MARKERrawdatastartshereanditcontinues. 最佳答案 Perl用__DATA__做这个:#!/usr/bin/perlusestrict;usewarnings;while(){print;}__DATA__Texttoprintgoeshere 关于ruby-如何将脚
我正在使用的第三方API的文档状态:"[O]urAPIonlyacceptspaddedBase64encodedstrings."什么是“填充的Base64编码字符串”以及如何在Ruby中生成它们。下面的代码是我第一次尝试创建转换为Base64的JSON格式数据。xa=Base64.encode64(a.to_json) 最佳答案 他们说的padding其实就是Base64本身的一部分。它是末尾的“=”和“==”。Base64将3个字节的数据包编码为4个编码字符。所以如果你的输入数据有长度n和n%3=1=>"=="末尾用于填充n%
我试图在索引页中创建一个超链接,但它没有显示,也没有给出任何错误。这是我的index.html.erb代码。ListingarticlesTitleTextssss我检查了我的路线,我认为它们也没有问题。PrefixVerbURIPatternController#Actionwelcome_indexGET/welcome/index(.:format)welcome#indexarticlesGET/articles(.:format)articles#indexPOST/articles(.:format)articles#createnew_articleGET/article
我有一个用户工厂。我希望默认情况下确认用户。但是鉴于unconfirmed特征,我不希望它们被确认。虽然我有一个基于实现细节而不是抽象的工作实现,但我想知道如何正确地做到这一点。factory:userdoafter(:create)do|user,evaluator|#unwantedimplementationdetailshereunlessFactoryGirl.factories[:user].defined_traits.map(&:name).include?(:unconfirmed)user.confirm!endendtrait:unconfirmeddoenden
我有一个驼峰式字符串,例如:JustAString。我想按照以下规则形成长度为4的字符串:抓取所有大写字母;如果超过4个大写字母,只保留前4个;如果少于4个大写字母,则将最后大写字母后的字母大写并添加字母,直到长度变为4。以下是可能发生的3种情况:ThisIsMyString将产生TIMS(大写字母);ThisIsOneVeryLongString将产生TIOV(前4个大写字母);MyString将生成MSTR(大写字母+tr大写)。我设法用这个片段解决了前两种情况:str.scan(/[A-Z]/).first(4).join但是,我不太确定如何最好地修改上面的代码片段以处理最后一种
我正在处理旧代码的一部分。beforedoallow_any_instance_of(SportRateManager).toreceive(:create).and_return(true)endRubocop错误如下:Avoidstubbingusing'allow_any_instance_of'我读到了RuboCop::RSpec:AnyInstance我试着像下面那样改变它。由此beforedoallow_any_instance_of(SportRateManager).toreceive(:create).and_return(true)end对此:let(:sport_
我需要一些关于TDD概念的帮助。假设我有以下代码defexecute(command)casecommandwhen"c"create_new_characterwhen"i"display_inventoryendenddefcreate_new_character#dostufftocreatenewcharacterenddefdisplay_inventory#dostufftodisplayinventoryend现在我不确定要为什么编写单元测试。如果我为execute方法编写单元测试,那不是几乎涵盖了我对create_new_character和display_invent
我只想对我一直在思考的这个问题有其他意见,例如我有classuser_controller和classuserclassUserattr_accessor:name,:usernameendclassUserController//dosomethingaboutanythingaboutusersend问题是我的User类中是否应该有逻辑user=User.newuser.do_something(user1)oritshouldbeuser_controller=UserController.newuser_controller.do_something(user1,user2)我
我有一个使用SeleniumWebdriver和Nokogiri的Ruby应用程序。我想选择一个类,然后对于那个类对应的每个div,我想根据div的内容执行一个Action。例如,我正在解析以下页面:https://www.google.com/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=puppies这是一个搜索结果页面,我正在寻找描述中包含“Adoption”一词的第一个结果。因此机器人应该寻找带有className:"result"的div,对于每个检查它的.descriptiondiv是否包含单词“adoption