以前看到一些flash制作的很酷炫的时钟,自己没有艺术细胞,UI设计就免了,稍微介绍一下实现,背 景换成比较炫的图片就可以成为比较炫的时钟了
实现原理是根据时间计算角度,再计算时钟指针的终点。
代码比较简单:
XAML:
<Canvas>
<Ellipse Stroke="Transparent" Width="120" Height="120">
<Ellipse.Fill>
<RadialGradientBrush>
<GradientStop Color="White" Offset="0"></GradientStop>
<GradientStop Color="#DBDDE6" Offset="0.7"></GradientStop>
<GradientStop Color="#ACABC4" Offset="1"></GradientStop>
</RadialGradientBrush>
</Ellipse.Fill>
</Ellipse>
<Line x:Name="lnHor" Stroke="Red" StrokeThickness="3" X1="60" Y1="60" X2="60" Y2="60"></Line>
<Line x:Name="lnMin" Stroke="Yellow" StrokeThickness="2" X1="60" Y1="60" X2="60" Y2="60"></Line>
<Line x:Name="lnSec" Stroke="Blue" StrokeThickness="2" X1="60" Y1="60" X2="60" Y2="60"></Line>
<Ellipse Stroke="White" Width="6" Height="6" Fill="Black" Canvas.Left="57" Canvas.Top="57">
</Ellipse>
</Canvas>